@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
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { HexString } from '@1inch/sdk-core';
|
|
2
|
+
import type { IArgsData } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @notice TWAP Hook with exponential dutch auction and illiquidity handling
|
|
5
|
+
* @dev Implements a TWAP (Time-Weighted Average Price) selling strategy with the following features:
|
|
6
|
+
* - Linear liquidity unlocking over time
|
|
7
|
+
* - Exponential price decay (dutch auction) for better price discovery
|
|
8
|
+
* - Automatic price bump after periods of insufficient liquidity
|
|
9
|
+
* - Minimum trade size enforcement during TWAP duration
|
|
10
|
+
*
|
|
11
|
+
* Minimum Trade Size (minTradeAmountOut):
|
|
12
|
+
* The minimum trade size protects against gas cost impact on execution price.
|
|
13
|
+
* It should be set 1000x+ larger than the expected transaction fees on the deployment network.
|
|
14
|
+
*
|
|
15
|
+
* For example:
|
|
16
|
+
* - Ethereum mainnet with $50 gas cost → minTradeAmountOut should be $50,000+
|
|
17
|
+
* - Arbitrum/Optimism with $0.50 gas cost → minTradeAmountOut should be $500+
|
|
18
|
+
* - BSC/Polygon with $0.05 gas cost → minTradeAmountOut should be $50+
|
|
19
|
+
*
|
|
20
|
+
* This ensures gas costs remain negligible (<0.1%) relative to trade value.
|
|
21
|
+
*
|
|
22
|
+
* Price Bump Configuration Guidelines:
|
|
23
|
+
*
|
|
24
|
+
* The priceBumpAfterIlliquidity compensates for mandatory waiting periods due to linear unlocking.
|
|
25
|
+
* Time to unlock minTradeAmountOut = (minTradeAmountOut / balance0) * duration
|
|
26
|
+
*
|
|
27
|
+
* Examples:
|
|
28
|
+
* - minTradeAmountOut = 0.1% of balance0, duration = 24h → 14.4 min to unlock each min trade
|
|
29
|
+
* Recommended bump: 1.05e18 - 1.10e18 (5-10%)
|
|
30
|
+
*
|
|
31
|
+
* - minTradeAmountOut = 1% of balance0, duration = 24h → 14.4 min to unlock each min trade
|
|
32
|
+
* Recommended bump: 1.10e18 - 1.20e18 (10-20%)
|
|
33
|
+
*
|
|
34
|
+
* - minTradeAmountOut = 5% of balance0, duration = 24h → 1.2 hours to unlock each min trade
|
|
35
|
+
* Recommended bump: 1.30e18 - 1.50e18 (30-50%)
|
|
36
|
+
*
|
|
37
|
+
* - minTradeAmountOut = 10% of balance0, duration = 24h → 2.4 hours to unlock each min trade
|
|
38
|
+
* Recommended bump: 1.50e18 - 2.00e18 (50-100%)
|
|
39
|
+
*
|
|
40
|
+
* Additional factors to consider:
|
|
41
|
+
* - Network gas costs: Higher gas requires larger bumps
|
|
42
|
+
* - Pair volatility: Volatile pairs need larger bumps to compensate for price risk
|
|
43
|
+
* - Market depth: Thin markets may need higher bumps to attract arbitrageurs
|
|
44
|
+
*
|
|
45
|
+
* The bump should ensure profitability after the mandatory waiting period.
|
|
46
|
+
*
|
|
47
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/TWAPSwap.sol#L104
|
|
48
|
+
*/
|
|
49
|
+
export declare class TWAPSwapArgs implements IArgsData {
|
|
50
|
+
readonly balanceIn: bigint;
|
|
51
|
+
readonly balanceOut: bigint;
|
|
52
|
+
readonly startTime: bigint;
|
|
53
|
+
readonly duration: bigint;
|
|
54
|
+
readonly priceBumpAfterIlliquidity: bigint;
|
|
55
|
+
readonly minTradeAmountOut: bigint;
|
|
56
|
+
static readonly CODER: any;
|
|
57
|
+
/**
|
|
58
|
+
* balanceIn - expected amount of token1 for initial price (uint256)
|
|
59
|
+
* balanceOut - total amount of token0 for TWAP (uint256)
|
|
60
|
+
* startTime - TWAP start time (uint256)
|
|
61
|
+
* duration - TWAP duration (uint256)
|
|
62
|
+
* priceBumpAfterIlliquidity - price jump when liquidity insufficient, e.g. 1.10e18 = +10% (uint256)
|
|
63
|
+
* minTradeAmountOut - minimum trade size for token0 (uint256)
|
|
64
|
+
**/
|
|
65
|
+
constructor(balanceIn: bigint, balanceOut: bigint, startTime: bigint, duration: bigint, priceBumpAfterIlliquidity: bigint, minTradeAmountOut: bigint);
|
|
66
|
+
/**
|
|
67
|
+
* Decodes hex data into TWAPSwapArgs instance
|
|
68
|
+
**/
|
|
69
|
+
static decode(data: HexString): TWAPSwapArgs;
|
|
70
|
+
toJSON(): Record<string, unknown>;
|
|
71
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { HexString } from '@1inch/sdk-core';
|
|
2
|
+
import type { IArgsData } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @notice TWAP Hook with exponential dutch auction and illiquidity handling
|
|
5
|
+
* @dev Implements a TWAP (Time-Weighted Average Price) selling strategy with the following features:
|
|
6
|
+
* - Linear liquidity unlocking over time
|
|
7
|
+
* - Exponential price decay (dutch auction) for better price discovery
|
|
8
|
+
* - Automatic price bump after periods of insufficient liquidity
|
|
9
|
+
* - Minimum trade size enforcement during TWAP duration
|
|
10
|
+
*
|
|
11
|
+
* Minimum Trade Size (minTradeAmountOut):
|
|
12
|
+
* The minimum trade size protects against gas cost impact on execution price.
|
|
13
|
+
* It should be set 1000x+ larger than the expected transaction fees on the deployment network.
|
|
14
|
+
*
|
|
15
|
+
* For example:
|
|
16
|
+
* - Ethereum mainnet with $50 gas cost → minTradeAmountOut should be $50,000+
|
|
17
|
+
* - Arbitrum/Optimism with $0.50 gas cost → minTradeAmountOut should be $500+
|
|
18
|
+
* - BSC/Polygon with $0.05 gas cost → minTradeAmountOut should be $50+
|
|
19
|
+
*
|
|
20
|
+
* This ensures gas costs remain negligible (<0.1%) relative to trade value.
|
|
21
|
+
*
|
|
22
|
+
* Price Bump Configuration Guidelines:
|
|
23
|
+
*
|
|
24
|
+
* The priceBumpAfterIlliquidity compensates for mandatory waiting periods due to linear unlocking.
|
|
25
|
+
* Time to unlock minTradeAmountOut = (minTradeAmountOut / balance0) * duration
|
|
26
|
+
*
|
|
27
|
+
* Examples:
|
|
28
|
+
* - minTradeAmountOut = 0.1% of balance0, duration = 24h → 14.4 min to unlock each min trade
|
|
29
|
+
* Recommended bump: 1.05e18 - 1.10e18 (5-10%)
|
|
30
|
+
*
|
|
31
|
+
* - minTradeAmountOut = 1% of balance0, duration = 24h → 14.4 min to unlock each min trade
|
|
32
|
+
* Recommended bump: 1.10e18 - 1.20e18 (10-20%)
|
|
33
|
+
*
|
|
34
|
+
* - minTradeAmountOut = 5% of balance0, duration = 24h → 1.2 hours to unlock each min trade
|
|
35
|
+
* Recommended bump: 1.30e18 - 1.50e18 (30-50%)
|
|
36
|
+
*
|
|
37
|
+
* - minTradeAmountOut = 10% of balance0, duration = 24h → 2.4 hours to unlock each min trade
|
|
38
|
+
* Recommended bump: 1.50e18 - 2.00e18 (50-100%)
|
|
39
|
+
*
|
|
40
|
+
* Additional factors to consider:
|
|
41
|
+
* - Network gas costs: Higher gas requires larger bumps
|
|
42
|
+
* - Pair volatility: Volatile pairs need larger bumps to compensate for price risk
|
|
43
|
+
* - Market depth: Thin markets may need higher bumps to attract arbitrageurs
|
|
44
|
+
*
|
|
45
|
+
* The bump should ensure profitability after the mandatory waiting period.
|
|
46
|
+
*
|
|
47
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/TWAPSwap.sol#L104
|
|
48
|
+
*/
|
|
49
|
+
export declare class TWAPSwapArgs implements IArgsData {
|
|
50
|
+
readonly balanceIn: bigint;
|
|
51
|
+
readonly balanceOut: bigint;
|
|
52
|
+
readonly startTime: bigint;
|
|
53
|
+
readonly duration: bigint;
|
|
54
|
+
readonly priceBumpAfterIlliquidity: bigint;
|
|
55
|
+
readonly minTradeAmountOut: bigint;
|
|
56
|
+
static readonly CODER: any;
|
|
57
|
+
/**
|
|
58
|
+
* balanceIn - expected amount of token1 for initial price (uint256)
|
|
59
|
+
* balanceOut - total amount of token0 for TWAP (uint256)
|
|
60
|
+
* startTime - TWAP start time (uint256)
|
|
61
|
+
* duration - TWAP duration (uint256)
|
|
62
|
+
* priceBumpAfterIlliquidity - price jump when liquidity insufficient, e.g. 1.10e18 = +10% (uint256)
|
|
63
|
+
* minTradeAmountOut - minimum trade size for token0 (uint256)
|
|
64
|
+
**/
|
|
65
|
+
constructor(balanceIn: bigint, balanceOut: bigint, startTime: bigint, duration: bigint, priceBumpAfterIlliquidity: bigint, minTradeAmountOut: bigint);
|
|
66
|
+
/**
|
|
67
|
+
* Decodes hex data into TWAPSwapArgs instance
|
|
68
|
+
**/
|
|
69
|
+
static decode(data: HexString): TWAPSwapArgs;
|
|
70
|
+
toJSON(): Record<string, unknown>;
|
|
71
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HexString } from '@1inch/sdk-core';
|
|
2
|
+
export interface IArgsCoder<T> {
|
|
3
|
+
decode(data: HexString): T;
|
|
4
|
+
encode(data: T): HexString;
|
|
5
|
+
}
|
|
6
|
+
export interface IArgsData {
|
|
7
|
+
toJSON(): Record<string | number, unknown> | null;
|
|
8
|
+
}
|
|
9
|
+
export interface IOpcode<T extends IArgsData = IArgsData> {
|
|
10
|
+
id: symbol;
|
|
11
|
+
argsCoder(): IArgsCoder<T>;
|
|
12
|
+
createIx(args: T): IInstruction<T>;
|
|
13
|
+
}
|
|
14
|
+
export interface IInstruction<T extends IArgsData = IArgsData> {
|
|
15
|
+
args: T;
|
|
16
|
+
opcode: IOpcode<T>;
|
|
17
|
+
toJSON(): Record<string | number, unknown>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HexString } from '@1inch/sdk-core';
|
|
2
|
+
export interface IArgsCoder<T> {
|
|
3
|
+
decode(data: HexString): T;
|
|
4
|
+
encode(data: T): HexString;
|
|
5
|
+
}
|
|
6
|
+
export interface IArgsData {
|
|
7
|
+
toJSON(): Record<string | number, unknown> | null;
|
|
8
|
+
}
|
|
9
|
+
export interface IOpcode<T extends IArgsData = IArgsData> {
|
|
10
|
+
id: symbol;
|
|
11
|
+
argsCoder(): IArgsCoder<T>;
|
|
12
|
+
createIx(args: T): IInstruction<T>;
|
|
13
|
+
}
|
|
14
|
+
export interface IInstruction<T extends IArgsData = IArgsData> {
|
|
15
|
+
args: T;
|
|
16
|
+
opcode: IOpcode<T>;
|
|
17
|
+
toJSON(): Record<string | number, unknown>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HexString } from '@1inch/sdk-core';
|
|
2
|
+
import { XycSwapXDArgs } from './xyc-swap-xd-args';
|
|
3
|
+
import type { IArgsCoder } from '../types';
|
|
4
|
+
export declare class XycSwapXDArgsCoder implements IArgsCoder<XycSwapXDArgs> {
|
|
5
|
+
encode(_args: XycSwapXDArgs): HexString;
|
|
6
|
+
decode(_data: HexString): XycSwapXDArgs;
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HexString } from '@1inch/sdk-core';
|
|
2
|
+
import { XycSwapXDArgs } from './xyc-swap-xd-args';
|
|
3
|
+
import type { IArgsCoder } from '../types';
|
|
4
|
+
export declare class XycSwapXDArgsCoder implements IArgsCoder<XycSwapXDArgs> {
|
|
5
|
+
encode(_args: XycSwapXDArgs): HexString;
|
|
6
|
+
decode(_data: HexString): XycSwapXDArgs;
|
|
7
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HexString } from '@1inch/sdk-core';
|
|
2
|
+
import type { IArgsData } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Arguments for xycSwapXD instruction (no arguments required)
|
|
5
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCSwap.sol#L15
|
|
6
|
+
**/
|
|
7
|
+
export declare class XycSwapXDArgs implements IArgsData {
|
|
8
|
+
static readonly CODER: any;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Decodes hex data into XycSwapXDArgs instance
|
|
12
|
+
**/
|
|
13
|
+
static decode(data: HexString): XycSwapXDArgs;
|
|
14
|
+
toJSON(): Record<string, unknown>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HexString } from '@1inch/sdk-core';
|
|
2
|
+
import type { IArgsData } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Arguments for xycSwapXD instruction (no arguments required)
|
|
5
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCSwap.sol#L15
|
|
6
|
+
**/
|
|
7
|
+
export declare class XycSwapXDArgs implements IArgsData {
|
|
8
|
+
static readonly CODER: any;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Decodes hex data into XycSwapXDArgs instance
|
|
12
|
+
**/
|
|
13
|
+
static decode(data: HexString): XycSwapXDArgs;
|
|
14
|
+
toJSON(): Record<string, unknown>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { DataFor } from '@1inch/sdk-core';
|
|
2
|
+
import { Interaction, HexString, Address } from '@1inch/sdk-core';
|
|
3
|
+
/**
|
|
4
|
+
* Maker-side order configuration packed into a single `uint256` and an optional hooks data blob.
|
|
5
|
+
*
|
|
6
|
+
* This class mirrors the on-chain `MakerTraits` bit layout and encoding used by the SwapVM
|
|
7
|
+
* contracts. It is responsible for:
|
|
8
|
+
*
|
|
9
|
+
* - maker preferences (unwrap WETH, allow zero amount in, Aqua vs signature)
|
|
10
|
+
* - selecting an optional custom receiver
|
|
11
|
+
* - wiring pre/post transfer hooks and their optional targets/payloads
|
|
12
|
+
*
|
|
13
|
+
* The ABI-level representation is:
|
|
14
|
+
* - `traits` – a `uint256` where:
|
|
15
|
+
* - high bits 245–255 store boolean flags
|
|
16
|
+
* - bits 160–223 store cumulative offsets for hook data slices (4 × `uint16`)
|
|
17
|
+
* - bits 0–159 store the receiver address (0 means "maker")
|
|
18
|
+
* - `hooksData` – concatenation of hook payloads in the order:
|
|
19
|
+
* `preTransferIn`, `postTransferIn`, `preTransferOut`, `postTransferOut`
|
|
20
|
+
*/
|
|
21
|
+
export declare class MakerTraits {
|
|
22
|
+
/**
|
|
23
|
+
* If true, maker WETH proceeds are unwrapped into the native currency when
|
|
24
|
+
* the order is settled.
|
|
25
|
+
*/
|
|
26
|
+
readonly shouldUnwrap: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* If true, the order is intended to be authenticated via Aqua (push-based
|
|
29
|
+
* mechanism) instead of a traditional ECDSA signature.
|
|
30
|
+
*/
|
|
31
|
+
readonly useAquaInsteadOfSignature: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* If true, the order accepts `amountIn = 0`. This is useful for flows
|
|
34
|
+
* where the effective input is determined by hooks or Aqua rather than the
|
|
35
|
+
* taker-supplied amount.
|
|
36
|
+
*/
|
|
37
|
+
readonly allowZeroAmountIn: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Optional receiver of the maker's output assets. When omitted or equal to
|
|
40
|
+
* the zero address, the maker address is used as the receiver.
|
|
41
|
+
*/
|
|
42
|
+
readonly customReceiver?: Address;
|
|
43
|
+
/**
|
|
44
|
+
* Optional hook executed before tokens are transferred *into* the maker
|
|
45
|
+
* side of the swap. The `Interaction` can carry both target and calldata.
|
|
46
|
+
* When the hook should be called on the maker itself, `Interaction.target`
|
|
47
|
+
* must be the zero address.
|
|
48
|
+
*/
|
|
49
|
+
readonly preTransferInHook?: Interaction;
|
|
50
|
+
/**
|
|
51
|
+
* Optional hook executed after tokens are transferred *into* the maker
|
|
52
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
53
|
+
* `Interaction.target` must be the zero address.
|
|
54
|
+
*/
|
|
55
|
+
readonly postTransferInHook?: Interaction;
|
|
56
|
+
/**
|
|
57
|
+
* Optional hook executed before tokens are transferred *out of* the maker
|
|
58
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
59
|
+
* `Interaction.target` must be the zero address.
|
|
60
|
+
*/
|
|
61
|
+
readonly preTransferOutHook?: Interaction;
|
|
62
|
+
/**
|
|
63
|
+
* Optional hook executed after tokens are transferred *out of* the maker
|
|
64
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
65
|
+
* `Interaction.target` must be the zero address.
|
|
66
|
+
*/
|
|
67
|
+
readonly postTransferOutHook?: Interaction;
|
|
68
|
+
private static HOOKS;
|
|
69
|
+
private static SHOULD_UNWRAP_BIT_FLAG;
|
|
70
|
+
private static USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG;
|
|
71
|
+
private static ALLOW_ZERO_AMOUNT_IN;
|
|
72
|
+
private static HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG;
|
|
73
|
+
private static HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG;
|
|
74
|
+
private static HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG;
|
|
75
|
+
private static HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG;
|
|
76
|
+
private static PRE_TRANSFER_IN_HOOK_HAS_TARGET;
|
|
77
|
+
private static POST_TRANSFER_IN_HOOK_HAS_TARGET;
|
|
78
|
+
private static PRE_TRANSFER_OUT_HOOK_HAS_TARGET;
|
|
79
|
+
private static POST_TRANSFER_OUT_HOOK_HAS_TARGET;
|
|
80
|
+
private static CUSTOM_RECEIVER_MASK;
|
|
81
|
+
private static HOOKS_DATA_OFFSETS_MASK;
|
|
82
|
+
constructor(
|
|
83
|
+
/**
|
|
84
|
+
* If true, maker WETH proceeds are unwrapped into the native currency when
|
|
85
|
+
* the order is settled.
|
|
86
|
+
*/
|
|
87
|
+
shouldUnwrap: boolean,
|
|
88
|
+
/**
|
|
89
|
+
* If true, the order is intended to be authenticated via Aqua (push-based
|
|
90
|
+
* mechanism) instead of a traditional ECDSA signature.
|
|
91
|
+
*/
|
|
92
|
+
useAquaInsteadOfSignature: boolean,
|
|
93
|
+
/**
|
|
94
|
+
* If true, the order accepts `amountIn = 0`. This is useful for flows
|
|
95
|
+
* where the effective input is determined by hooks or Aqua rather than the
|
|
96
|
+
* taker-supplied amount.
|
|
97
|
+
*/
|
|
98
|
+
allowZeroAmountIn: boolean,
|
|
99
|
+
/**
|
|
100
|
+
* Optional receiver of the maker's output assets. When omitted or equal to
|
|
101
|
+
* the zero address, the maker address is used as the receiver.
|
|
102
|
+
*/
|
|
103
|
+
customReceiver?: Address,
|
|
104
|
+
/**
|
|
105
|
+
* Optional hook executed before tokens are transferred *into* the maker
|
|
106
|
+
* side of the swap. The `Interaction` can carry both target and calldata.
|
|
107
|
+
* When the hook should be called on the maker itself, `Interaction.target`
|
|
108
|
+
* must be the zero address.
|
|
109
|
+
*/
|
|
110
|
+
preTransferInHook?: Interaction,
|
|
111
|
+
/**
|
|
112
|
+
* Optional hook executed after tokens are transferred *into* the maker
|
|
113
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
114
|
+
* `Interaction.target` must be the zero address.
|
|
115
|
+
*/
|
|
116
|
+
postTransferInHook?: Interaction,
|
|
117
|
+
/**
|
|
118
|
+
* Optional hook executed before tokens are transferred *out of* the maker
|
|
119
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
120
|
+
* `Interaction.target` must be the zero address.
|
|
121
|
+
*/
|
|
122
|
+
preTransferOutHook?: Interaction,
|
|
123
|
+
/**
|
|
124
|
+
* Optional hook executed after tokens are transferred *out of* the maker
|
|
125
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
126
|
+
* `Interaction.target` must be the zero address.
|
|
127
|
+
*/
|
|
128
|
+
postTransferOutHook?: Interaction);
|
|
129
|
+
/**
|
|
130
|
+
* Construct traits from a plain data object.
|
|
131
|
+
*/
|
|
132
|
+
static new(data: DataFor<MakerTraits>): MakerTraits;
|
|
133
|
+
/**
|
|
134
|
+
* Create traits with library defaults that match the on-chain SwapVM expectations:
|
|
135
|
+
* - `useAquaInsteadOfSignature` = `true`
|
|
136
|
+
* - `shouldUnwrap` = `false`
|
|
137
|
+
* - `allowZeroAmountIn` = `false`
|
|
138
|
+
* - no receiver or hooks configured.
|
|
139
|
+
*/
|
|
140
|
+
static default(): MakerTraits;
|
|
141
|
+
/**
|
|
142
|
+
* Decode ABI-level representation into a `MakerTraits` instance.
|
|
143
|
+
*
|
|
144
|
+
* @param traits Packed `uint256` bitfield as produced by {@link encode}.
|
|
145
|
+
* @param hooksData Concatenated hooks payloads in the format expected by SwapVM
|
|
146
|
+
* contracts (may be `HexString.EMPTY` when no hooks are present).
|
|
147
|
+
*
|
|
148
|
+
* Both arguments are typically obtained from contract storage / ABI and must
|
|
149
|
+
* follow the bit layout described in the class-level documentation.
|
|
150
|
+
*/
|
|
151
|
+
static decode(traits: bigint, hooksData?: any): MakerTraits;
|
|
152
|
+
static hooksDataEndsAtByte(traits: bigint): number;
|
|
153
|
+
/**
|
|
154
|
+
* Mutate the traits instance in-place with a partial update and return it.
|
|
155
|
+
*
|
|
156
|
+
* This is primarily used for fluent-style construction in tests and examples, e.g.:
|
|
157
|
+
*
|
|
158
|
+
* `MakerTraits.default().with({ shouldUnwrap: true })`
|
|
159
|
+
*
|
|
160
|
+
* Only fields present in `data` are updated; flags, receiver, and hooks can be
|
|
161
|
+
* changed independently.
|
|
162
|
+
*/
|
|
163
|
+
with(data: Partial<DataFor<MakerTraits>>): this;
|
|
164
|
+
/**
|
|
165
|
+
* Encode traits into the ABI format expected by SwapVM contracts.
|
|
166
|
+
*
|
|
167
|
+
* @param maker - Maker address for this order. This parameter is required only
|
|
168
|
+
* for gas/size optimisation; if omitted, any non-zero hook `target`
|
|
169
|
+
* is treated as an explicit target.
|
|
170
|
+
*
|
|
171
|
+
* @returns An object containing:
|
|
172
|
+
* - `traits` - Packed `uint256` bitfield with flags, receiver and offsets
|
|
173
|
+
* - `hooksData` - Concatenation of hook segments for all configured hooks
|
|
174
|
+
*
|
|
175
|
+
* ## Bit Layout of `traits` (uint256)
|
|
176
|
+
*
|
|
177
|
+
* ```
|
|
178
|
+
* 255 0
|
|
179
|
+
* +------------+----------------------------+------------------+
|
|
180
|
+
* | Flags | Hook Offsets (4×uint16) | Receiver Address |
|
|
181
|
+
* | [255-245] | [223-160] | [159-0] |
|
|
182
|
+
* +------------+----------------------------+------------------+
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* ## Flags (by bit index)
|
|
186
|
+
*
|
|
187
|
+
* | Bit | Flag Name |
|
|
188
|
+
* |-----|------------------------------------------|
|
|
189
|
+
* | 255 | SHOULD_UNWRAP_BIT_FLAG |
|
|
190
|
+
* | 254 | USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG |
|
|
191
|
+
* | 253 | ALLOW_ZERO_AMOUNT_IN |
|
|
192
|
+
* | 252 | HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG |
|
|
193
|
+
* | 251 | HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG |
|
|
194
|
+
* | 250 | HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG |
|
|
195
|
+
* | 249 | HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG |
|
|
196
|
+
* | 248 | PRE_TRANSFER_IN_HOOK_HAS_TARGET |
|
|
197
|
+
* | 247 | POST_TRANSFER_IN_HOOK_HAS_TARGET |
|
|
198
|
+
* | 246 | PRE_TRANSFER_OUT_HOOK_HAS_TARGET |
|
|
199
|
+
* | 245 | POST_TRANSFER_OUT_HOOK_HAS_TARGET |
|
|
200
|
+
*/
|
|
201
|
+
encode(maker?: Address): {
|
|
202
|
+
traits: bigint;
|
|
203
|
+
hooksData: HexString;
|
|
204
|
+
};
|
|
205
|
+
private hasTargetForHook;
|
|
206
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { DataFor } from '@1inch/sdk-core';
|
|
2
|
+
import { Interaction, HexString, Address } from '@1inch/sdk-core';
|
|
3
|
+
/**
|
|
4
|
+
* Maker-side order configuration packed into a single `uint256` and an optional hooks data blob.
|
|
5
|
+
*
|
|
6
|
+
* This class mirrors the on-chain `MakerTraits` bit layout and encoding used by the SwapVM
|
|
7
|
+
* contracts. It is responsible for:
|
|
8
|
+
*
|
|
9
|
+
* - maker preferences (unwrap WETH, allow zero amount in, Aqua vs signature)
|
|
10
|
+
* - selecting an optional custom receiver
|
|
11
|
+
* - wiring pre/post transfer hooks and their optional targets/payloads
|
|
12
|
+
*
|
|
13
|
+
* The ABI-level representation is:
|
|
14
|
+
* - `traits` – a `uint256` where:
|
|
15
|
+
* - high bits 245–255 store boolean flags
|
|
16
|
+
* - bits 160–223 store cumulative offsets for hook data slices (4 × `uint16`)
|
|
17
|
+
* - bits 0–159 store the receiver address (0 means "maker")
|
|
18
|
+
* - `hooksData` – concatenation of hook payloads in the order:
|
|
19
|
+
* `preTransferIn`, `postTransferIn`, `preTransferOut`, `postTransferOut`
|
|
20
|
+
*/
|
|
21
|
+
export declare class MakerTraits {
|
|
22
|
+
/**
|
|
23
|
+
* If true, maker WETH proceeds are unwrapped into the native currency when
|
|
24
|
+
* the order is settled.
|
|
25
|
+
*/
|
|
26
|
+
readonly shouldUnwrap: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* If true, the order is intended to be authenticated via Aqua (push-based
|
|
29
|
+
* mechanism) instead of a traditional ECDSA signature.
|
|
30
|
+
*/
|
|
31
|
+
readonly useAquaInsteadOfSignature: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* If true, the order accepts `amountIn = 0`. This is useful for flows
|
|
34
|
+
* where the effective input is determined by hooks or Aqua rather than the
|
|
35
|
+
* taker-supplied amount.
|
|
36
|
+
*/
|
|
37
|
+
readonly allowZeroAmountIn: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Optional receiver of the maker's output assets. When omitted or equal to
|
|
40
|
+
* the zero address, the maker address is used as the receiver.
|
|
41
|
+
*/
|
|
42
|
+
readonly customReceiver?: Address;
|
|
43
|
+
/**
|
|
44
|
+
* Optional hook executed before tokens are transferred *into* the maker
|
|
45
|
+
* side of the swap. The `Interaction` can carry both target and calldata.
|
|
46
|
+
* When the hook should be called on the maker itself, `Interaction.target`
|
|
47
|
+
* must be the zero address.
|
|
48
|
+
*/
|
|
49
|
+
readonly preTransferInHook?: Interaction;
|
|
50
|
+
/**
|
|
51
|
+
* Optional hook executed after tokens are transferred *into* the maker
|
|
52
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
53
|
+
* `Interaction.target` must be the zero address.
|
|
54
|
+
*/
|
|
55
|
+
readonly postTransferInHook?: Interaction;
|
|
56
|
+
/**
|
|
57
|
+
* Optional hook executed before tokens are transferred *out of* the maker
|
|
58
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
59
|
+
* `Interaction.target` must be the zero address.
|
|
60
|
+
*/
|
|
61
|
+
readonly preTransferOutHook?: Interaction;
|
|
62
|
+
/**
|
|
63
|
+
* Optional hook executed after tokens are transferred *out of* the maker
|
|
64
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
65
|
+
* `Interaction.target` must be the zero address.
|
|
66
|
+
*/
|
|
67
|
+
readonly postTransferOutHook?: Interaction;
|
|
68
|
+
private static HOOKS;
|
|
69
|
+
private static SHOULD_UNWRAP_BIT_FLAG;
|
|
70
|
+
private static USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG;
|
|
71
|
+
private static ALLOW_ZERO_AMOUNT_IN;
|
|
72
|
+
private static HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG;
|
|
73
|
+
private static HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG;
|
|
74
|
+
private static HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG;
|
|
75
|
+
private static HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG;
|
|
76
|
+
private static PRE_TRANSFER_IN_HOOK_HAS_TARGET;
|
|
77
|
+
private static POST_TRANSFER_IN_HOOK_HAS_TARGET;
|
|
78
|
+
private static PRE_TRANSFER_OUT_HOOK_HAS_TARGET;
|
|
79
|
+
private static POST_TRANSFER_OUT_HOOK_HAS_TARGET;
|
|
80
|
+
private static CUSTOM_RECEIVER_MASK;
|
|
81
|
+
private static HOOKS_DATA_OFFSETS_MASK;
|
|
82
|
+
constructor(
|
|
83
|
+
/**
|
|
84
|
+
* If true, maker WETH proceeds are unwrapped into the native currency when
|
|
85
|
+
* the order is settled.
|
|
86
|
+
*/
|
|
87
|
+
shouldUnwrap: boolean,
|
|
88
|
+
/**
|
|
89
|
+
* If true, the order is intended to be authenticated via Aqua (push-based
|
|
90
|
+
* mechanism) instead of a traditional ECDSA signature.
|
|
91
|
+
*/
|
|
92
|
+
useAquaInsteadOfSignature: boolean,
|
|
93
|
+
/**
|
|
94
|
+
* If true, the order accepts `amountIn = 0`. This is useful for flows
|
|
95
|
+
* where the effective input is determined by hooks or Aqua rather than the
|
|
96
|
+
* taker-supplied amount.
|
|
97
|
+
*/
|
|
98
|
+
allowZeroAmountIn: boolean,
|
|
99
|
+
/**
|
|
100
|
+
* Optional receiver of the maker's output assets. When omitted or equal to
|
|
101
|
+
* the zero address, the maker address is used as the receiver.
|
|
102
|
+
*/
|
|
103
|
+
customReceiver?: Address,
|
|
104
|
+
/**
|
|
105
|
+
* Optional hook executed before tokens are transferred *into* the maker
|
|
106
|
+
* side of the swap. The `Interaction` can carry both target and calldata.
|
|
107
|
+
* When the hook should be called on the maker itself, `Interaction.target`
|
|
108
|
+
* must be the zero address.
|
|
109
|
+
*/
|
|
110
|
+
preTransferInHook?: Interaction,
|
|
111
|
+
/**
|
|
112
|
+
* Optional hook executed after tokens are transferred *into* the maker
|
|
113
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
114
|
+
* `Interaction.target` must be the zero address.
|
|
115
|
+
*/
|
|
116
|
+
postTransferInHook?: Interaction,
|
|
117
|
+
/**
|
|
118
|
+
* Optional hook executed before tokens are transferred *out of* the maker
|
|
119
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
120
|
+
* `Interaction.target` must be the zero address.
|
|
121
|
+
*/
|
|
122
|
+
preTransferOutHook?: Interaction,
|
|
123
|
+
/**
|
|
124
|
+
* Optional hook executed after tokens are transferred *out of* the maker
|
|
125
|
+
* side of the swap. When the hook should be called on the maker itself,
|
|
126
|
+
* `Interaction.target` must be the zero address.
|
|
127
|
+
*/
|
|
128
|
+
postTransferOutHook?: Interaction);
|
|
129
|
+
/**
|
|
130
|
+
* Construct traits from a plain data object.
|
|
131
|
+
*/
|
|
132
|
+
static new(data: DataFor<MakerTraits>): MakerTraits;
|
|
133
|
+
/**
|
|
134
|
+
* Create traits with library defaults that match the on-chain SwapVM expectations:
|
|
135
|
+
* - `useAquaInsteadOfSignature` = `true`
|
|
136
|
+
* - `shouldUnwrap` = `false`
|
|
137
|
+
* - `allowZeroAmountIn` = `false`
|
|
138
|
+
* - no receiver or hooks configured.
|
|
139
|
+
*/
|
|
140
|
+
static default(): MakerTraits;
|
|
141
|
+
/**
|
|
142
|
+
* Decode ABI-level representation into a `MakerTraits` instance.
|
|
143
|
+
*
|
|
144
|
+
* @param traits Packed `uint256` bitfield as produced by {@link encode}.
|
|
145
|
+
* @param hooksData Concatenated hooks payloads in the format expected by SwapVM
|
|
146
|
+
* contracts (may be `HexString.EMPTY` when no hooks are present).
|
|
147
|
+
*
|
|
148
|
+
* Both arguments are typically obtained from contract storage / ABI and must
|
|
149
|
+
* follow the bit layout described in the class-level documentation.
|
|
150
|
+
*/
|
|
151
|
+
static decode(traits: bigint, hooksData?: any): MakerTraits;
|
|
152
|
+
static hooksDataEndsAtByte(traits: bigint): number;
|
|
153
|
+
/**
|
|
154
|
+
* Mutate the traits instance in-place with a partial update and return it.
|
|
155
|
+
*
|
|
156
|
+
* This is primarily used for fluent-style construction in tests and examples, e.g.:
|
|
157
|
+
*
|
|
158
|
+
* `MakerTraits.default().with({ shouldUnwrap: true })`
|
|
159
|
+
*
|
|
160
|
+
* Only fields present in `data` are updated; flags, receiver, and hooks can be
|
|
161
|
+
* changed independently.
|
|
162
|
+
*/
|
|
163
|
+
with(data: Partial<DataFor<MakerTraits>>): this;
|
|
164
|
+
/**
|
|
165
|
+
* Encode traits into the ABI format expected by SwapVM contracts.
|
|
166
|
+
*
|
|
167
|
+
* @param maker - Maker address for this order. This parameter is required only
|
|
168
|
+
* for gas/size optimisation; if omitted, any non-zero hook `target`
|
|
169
|
+
* is treated as an explicit target.
|
|
170
|
+
*
|
|
171
|
+
* @returns An object containing:
|
|
172
|
+
* - `traits` - Packed `uint256` bitfield with flags, receiver and offsets
|
|
173
|
+
* - `hooksData` - Concatenation of hook segments for all configured hooks
|
|
174
|
+
*
|
|
175
|
+
* ## Bit Layout of `traits` (uint256)
|
|
176
|
+
*
|
|
177
|
+
* ```
|
|
178
|
+
* 255 0
|
|
179
|
+
* +------------+----------------------------+------------------+
|
|
180
|
+
* | Flags | Hook Offsets (4×uint16) | Receiver Address |
|
|
181
|
+
* | [255-245] | [223-160] | [159-0] |
|
|
182
|
+
* +------------+----------------------------+------------------+
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* ## Flags (by bit index)
|
|
186
|
+
*
|
|
187
|
+
* | Bit | Flag Name |
|
|
188
|
+
* |-----|------------------------------------------|
|
|
189
|
+
* | 255 | SHOULD_UNWRAP_BIT_FLAG |
|
|
190
|
+
* | 254 | USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG |
|
|
191
|
+
* | 253 | ALLOW_ZERO_AMOUNT_IN |
|
|
192
|
+
* | 252 | HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG |
|
|
193
|
+
* | 251 | HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG |
|
|
194
|
+
* | 250 | HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG |
|
|
195
|
+
* | 249 | HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG |
|
|
196
|
+
* | 248 | PRE_TRANSFER_IN_HOOK_HAS_TARGET |
|
|
197
|
+
* | 247 | POST_TRANSFER_IN_HOOK_HAS_TARGET |
|
|
198
|
+
* | 246 | PRE_TRANSFER_OUT_HOOK_HAS_TARGET |
|
|
199
|
+
* | 245 | POST_TRANSFER_OUT_HOOK_HAS_TARGET |
|
|
200
|
+
*/
|
|
201
|
+
encode(maker?: Address): {
|
|
202
|
+
traits: bigint;
|
|
203
|
+
hooksData: HexString;
|
|
204
|
+
};
|
|
205
|
+
private hasTargetForHook;
|
|
206
|
+
}
|