@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/dist/index.js
ADDED
|
@@ -0,0 +1,3842 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
|
+
key = keys[i];
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: ((k) => from[k]).bind(null, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
const viem = __toESM(require("viem"));
|
|
31
|
+
const __1inch_sdk_core = __toESM(require("@1inch/sdk-core"));
|
|
32
|
+
const __1inch_byte_utils = __toESM(require("@1inch/byte-utils"));
|
|
33
|
+
const assert = __toESM(require("assert"));
|
|
34
|
+
const node_assert = __toESM(require("node:assert"));
|
|
35
|
+
|
|
36
|
+
//#region src/abi/SwapVM.abi.ts
|
|
37
|
+
const SWAP_VM_ABI = [
|
|
38
|
+
{
|
|
39
|
+
type: "function",
|
|
40
|
+
name: "AQUA",
|
|
41
|
+
inputs: [],
|
|
42
|
+
outputs: [{
|
|
43
|
+
name: "",
|
|
44
|
+
type: "address",
|
|
45
|
+
internalType: "contract IAqua"
|
|
46
|
+
}],
|
|
47
|
+
stateMutability: "view"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "function",
|
|
51
|
+
name: "ORDER_TYPEHASH",
|
|
52
|
+
inputs: [],
|
|
53
|
+
outputs: [{
|
|
54
|
+
name: "",
|
|
55
|
+
type: "bytes32",
|
|
56
|
+
internalType: "bytes32"
|
|
57
|
+
}],
|
|
58
|
+
stateMutability: "view"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: "function",
|
|
62
|
+
name: "asView",
|
|
63
|
+
inputs: [],
|
|
64
|
+
outputs: [{
|
|
65
|
+
name: "",
|
|
66
|
+
type: "address",
|
|
67
|
+
internalType: "contract ISwapVM"
|
|
68
|
+
}],
|
|
69
|
+
stateMutability: "view"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: "function",
|
|
73
|
+
name: "eip712Domain",
|
|
74
|
+
inputs: [],
|
|
75
|
+
outputs: [
|
|
76
|
+
{
|
|
77
|
+
name: "fields",
|
|
78
|
+
type: "bytes1",
|
|
79
|
+
internalType: "bytes1"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "name",
|
|
83
|
+
type: "string",
|
|
84
|
+
internalType: "string"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "version",
|
|
88
|
+
type: "string",
|
|
89
|
+
internalType: "string"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: "chainId",
|
|
93
|
+
type: "uint256",
|
|
94
|
+
internalType: "uint256"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "verifyingContract",
|
|
98
|
+
type: "address",
|
|
99
|
+
internalType: "address"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "salt",
|
|
103
|
+
type: "bytes32",
|
|
104
|
+
internalType: "bytes32"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: "extensions",
|
|
108
|
+
type: "uint256[]",
|
|
109
|
+
internalType: "uint256[]"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
stateMutability: "view"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
type: "function",
|
|
116
|
+
name: "hash",
|
|
117
|
+
inputs: [{
|
|
118
|
+
name: "order",
|
|
119
|
+
type: "tuple",
|
|
120
|
+
internalType: "struct ISwapVM.Order",
|
|
121
|
+
components: [
|
|
122
|
+
{
|
|
123
|
+
name: "maker",
|
|
124
|
+
type: "address",
|
|
125
|
+
internalType: "address"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: "traits",
|
|
129
|
+
type: "uint256",
|
|
130
|
+
internalType: "MakerTraits"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "data",
|
|
134
|
+
type: "bytes",
|
|
135
|
+
internalType: "bytes"
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
}],
|
|
139
|
+
outputs: [{
|
|
140
|
+
name: "",
|
|
141
|
+
type: "bytes32",
|
|
142
|
+
internalType: "bytes32"
|
|
143
|
+
}],
|
|
144
|
+
stateMutability: "view"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
type: "function",
|
|
148
|
+
name: "quote",
|
|
149
|
+
inputs: [
|
|
150
|
+
{
|
|
151
|
+
name: "order",
|
|
152
|
+
type: "tuple",
|
|
153
|
+
internalType: "struct ISwapVM.Order",
|
|
154
|
+
components: [
|
|
155
|
+
{
|
|
156
|
+
name: "maker",
|
|
157
|
+
type: "address",
|
|
158
|
+
internalType: "address"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: "traits",
|
|
162
|
+
type: "uint256",
|
|
163
|
+
internalType: "MakerTraits"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: "data",
|
|
167
|
+
type: "bytes",
|
|
168
|
+
internalType: "bytes"
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: "tokenIn",
|
|
174
|
+
type: "address",
|
|
175
|
+
internalType: "address"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "tokenOut",
|
|
179
|
+
type: "address",
|
|
180
|
+
internalType: "address"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: "amount",
|
|
184
|
+
type: "uint256",
|
|
185
|
+
internalType: "uint256"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
name: "takerTraitsAndData",
|
|
189
|
+
type: "bytes",
|
|
190
|
+
internalType: "bytes"
|
|
191
|
+
}
|
|
192
|
+
],
|
|
193
|
+
outputs: [
|
|
194
|
+
{
|
|
195
|
+
name: "amountIn",
|
|
196
|
+
type: "uint256",
|
|
197
|
+
internalType: "uint256"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: "amountOut",
|
|
201
|
+
type: "uint256",
|
|
202
|
+
internalType: "uint256"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "orderHash",
|
|
206
|
+
type: "bytes32",
|
|
207
|
+
internalType: "bytes32"
|
|
208
|
+
}
|
|
209
|
+
],
|
|
210
|
+
stateMutability: "nonpayable"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
type: "function",
|
|
214
|
+
name: "swap",
|
|
215
|
+
inputs: [
|
|
216
|
+
{
|
|
217
|
+
name: "order",
|
|
218
|
+
type: "tuple",
|
|
219
|
+
internalType: "struct ISwapVM.Order",
|
|
220
|
+
components: [
|
|
221
|
+
{
|
|
222
|
+
name: "maker",
|
|
223
|
+
type: "address",
|
|
224
|
+
internalType: "address"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
name: "traits",
|
|
228
|
+
type: "uint256",
|
|
229
|
+
internalType: "MakerTraits"
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: "data",
|
|
233
|
+
type: "bytes",
|
|
234
|
+
internalType: "bytes"
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: "tokenIn",
|
|
240
|
+
type: "address",
|
|
241
|
+
internalType: "address"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: "tokenOut",
|
|
245
|
+
type: "address",
|
|
246
|
+
internalType: "address"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "amount",
|
|
250
|
+
type: "uint256",
|
|
251
|
+
internalType: "uint256"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: "takerTraitsAndData",
|
|
255
|
+
type: "bytes",
|
|
256
|
+
internalType: "bytes"
|
|
257
|
+
}
|
|
258
|
+
],
|
|
259
|
+
outputs: [
|
|
260
|
+
{
|
|
261
|
+
name: "amountIn",
|
|
262
|
+
type: "uint256",
|
|
263
|
+
internalType: "uint256"
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: "amountOut",
|
|
267
|
+
type: "uint256",
|
|
268
|
+
internalType: "uint256"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: "orderHash",
|
|
272
|
+
type: "bytes32",
|
|
273
|
+
internalType: "bytes32"
|
|
274
|
+
}
|
|
275
|
+
],
|
|
276
|
+
stateMutability: "nonpayable"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
type: "event",
|
|
280
|
+
name: "EIP712DomainChanged",
|
|
281
|
+
inputs: [],
|
|
282
|
+
anonymous: false
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
type: "event",
|
|
286
|
+
name: "Swapped",
|
|
287
|
+
inputs: [
|
|
288
|
+
{
|
|
289
|
+
name: "orderHash",
|
|
290
|
+
type: "bytes32",
|
|
291
|
+
indexed: false,
|
|
292
|
+
internalType: "bytes32"
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
name: "maker",
|
|
296
|
+
type: "address",
|
|
297
|
+
indexed: false,
|
|
298
|
+
internalType: "address"
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: "taker",
|
|
302
|
+
type: "address",
|
|
303
|
+
indexed: false,
|
|
304
|
+
internalType: "address"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: "tokenIn",
|
|
308
|
+
type: "address",
|
|
309
|
+
indexed: false,
|
|
310
|
+
internalType: "address"
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
name: "tokenOut",
|
|
314
|
+
type: "address",
|
|
315
|
+
indexed: false,
|
|
316
|
+
internalType: "address"
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
name: "amountIn",
|
|
320
|
+
type: "uint256",
|
|
321
|
+
indexed: false,
|
|
322
|
+
internalType: "uint256"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
name: "amountOut",
|
|
326
|
+
type: "uint256",
|
|
327
|
+
indexed: false,
|
|
328
|
+
internalType: "uint256"
|
|
329
|
+
}
|
|
330
|
+
],
|
|
331
|
+
anonymous: false
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
type: "error",
|
|
335
|
+
name: "AquaBalanceInsufficientAfterTakerPush",
|
|
336
|
+
inputs: [
|
|
337
|
+
{
|
|
338
|
+
name: "balance",
|
|
339
|
+
type: "uint256",
|
|
340
|
+
internalType: "uint256"
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
name: "preBalance",
|
|
344
|
+
type: "uint256",
|
|
345
|
+
internalType: "uint256"
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: "amount",
|
|
349
|
+
type: "uint256",
|
|
350
|
+
internalType: "uint256"
|
|
351
|
+
}
|
|
352
|
+
]
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
type: "error",
|
|
356
|
+
name: "BadSignature",
|
|
357
|
+
inputs: [
|
|
358
|
+
{
|
|
359
|
+
name: "maker",
|
|
360
|
+
type: "address",
|
|
361
|
+
internalType: "address"
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
name: "orderHash",
|
|
365
|
+
type: "bytes32",
|
|
366
|
+
internalType: "bytes32"
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: "signature",
|
|
370
|
+
type: "bytes",
|
|
371
|
+
internalType: "bytes"
|
|
372
|
+
}
|
|
373
|
+
]
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
type: "error",
|
|
377
|
+
name: "ForceApproveFailed",
|
|
378
|
+
inputs: []
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
type: "error",
|
|
382
|
+
name: "InvalidShortString",
|
|
383
|
+
inputs: []
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
type: "error",
|
|
387
|
+
name: "MakerTraitsCustomReceiverIsIncompatibleWithAqua",
|
|
388
|
+
inputs: []
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
type: "error",
|
|
392
|
+
name: "MakerTraitsTokenInAndTokenOutMustBeDifferent",
|
|
393
|
+
inputs: []
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
type: "error",
|
|
397
|
+
name: "MakerTraitsUnwrapIsIncompatibleWithAqua",
|
|
398
|
+
inputs: []
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
type: "error",
|
|
402
|
+
name: "MakerTraitsZeroAmountInNotAllowed",
|
|
403
|
+
inputs: []
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
type: "error",
|
|
407
|
+
name: "RunLoopExcessiveCall",
|
|
408
|
+
inputs: [{
|
|
409
|
+
name: "pc",
|
|
410
|
+
type: "uint256",
|
|
411
|
+
internalType: "uint256"
|
|
412
|
+
}, {
|
|
413
|
+
name: "programLength",
|
|
414
|
+
type: "uint256",
|
|
415
|
+
internalType: "uint256"
|
|
416
|
+
}]
|
|
417
|
+
},
|
|
418
|
+
{
|
|
419
|
+
type: "error",
|
|
420
|
+
name: "SafeTransferFromFailed",
|
|
421
|
+
inputs: []
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
type: "error",
|
|
425
|
+
name: "StringTooLong",
|
|
426
|
+
inputs: [{
|
|
427
|
+
name: "str",
|
|
428
|
+
type: "string",
|
|
429
|
+
internalType: "string"
|
|
430
|
+
}]
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
type: "error",
|
|
434
|
+
name: "TakerTraitsAmountOutMustBeGreaterThanZero",
|
|
435
|
+
inputs: [{
|
|
436
|
+
name: "amountOut",
|
|
437
|
+
type: "uint256",
|
|
438
|
+
internalType: "uint256"
|
|
439
|
+
}]
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
type: "error",
|
|
443
|
+
name: "TakerTraitsExceedingMaxInputAmount",
|
|
444
|
+
inputs: [{
|
|
445
|
+
name: "amountIn",
|
|
446
|
+
type: "uint256",
|
|
447
|
+
internalType: "uint256"
|
|
448
|
+
}, {
|
|
449
|
+
name: "amountInMax",
|
|
450
|
+
type: "uint256",
|
|
451
|
+
internalType: "uint256"
|
|
452
|
+
}]
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
type: "error",
|
|
456
|
+
name: "TakerTraitsInsufficientMinOutputAmount",
|
|
457
|
+
inputs: [{
|
|
458
|
+
name: "amountOut",
|
|
459
|
+
type: "uint256",
|
|
460
|
+
internalType: "uint256"
|
|
461
|
+
}, {
|
|
462
|
+
name: "amountOutMin",
|
|
463
|
+
type: "uint256",
|
|
464
|
+
internalType: "uint256"
|
|
465
|
+
}]
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
type: "error",
|
|
469
|
+
name: "TakerTraitsNonExactThresholdAmountIn",
|
|
470
|
+
inputs: [{
|
|
471
|
+
name: "amountIn",
|
|
472
|
+
type: "uint256",
|
|
473
|
+
internalType: "uint256"
|
|
474
|
+
}, {
|
|
475
|
+
name: "amountThreshold",
|
|
476
|
+
type: "uint256",
|
|
477
|
+
internalType: "uint256"
|
|
478
|
+
}]
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
type: "error",
|
|
482
|
+
name: "TakerTraitsNonExactThresholdAmountOut",
|
|
483
|
+
inputs: [{
|
|
484
|
+
name: "amountOut",
|
|
485
|
+
type: "uint256",
|
|
486
|
+
internalType: "uint256"
|
|
487
|
+
}, {
|
|
488
|
+
name: "amountThreshold",
|
|
489
|
+
type: "uint256",
|
|
490
|
+
internalType: "uint256"
|
|
491
|
+
}]
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
type: "error",
|
|
495
|
+
name: "TakerTraitsTakerAmountInMismatch",
|
|
496
|
+
inputs: [{
|
|
497
|
+
name: "takerAmount",
|
|
498
|
+
type: "uint256",
|
|
499
|
+
internalType: "uint256"
|
|
500
|
+
}, {
|
|
501
|
+
name: "computedAmount",
|
|
502
|
+
type: "uint256",
|
|
503
|
+
internalType: "uint256"
|
|
504
|
+
}]
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
type: "error",
|
|
508
|
+
name: "TakerTraitsTakerAmountOutMismatch",
|
|
509
|
+
inputs: [{
|
|
510
|
+
name: "takerAmount",
|
|
511
|
+
type: "uint256",
|
|
512
|
+
internalType: "uint256"
|
|
513
|
+
}, {
|
|
514
|
+
name: "computedAmount",
|
|
515
|
+
type: "uint256",
|
|
516
|
+
internalType: "uint256"
|
|
517
|
+
}]
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
type: "error",
|
|
521
|
+
name: "UnexpectedLock",
|
|
522
|
+
inputs: []
|
|
523
|
+
}
|
|
524
|
+
];
|
|
525
|
+
|
|
526
|
+
//#endregion
|
|
527
|
+
//#region src/swap-vm-contract/swap-vm-contract.ts
|
|
528
|
+
/**
|
|
529
|
+
* SwapVM contract encoding/decoding utilities
|
|
530
|
+
*/
|
|
531
|
+
var SwapVMContract = class SwapVMContract {
|
|
532
|
+
constructor(address) {
|
|
533
|
+
this.address = address;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Encode quote function call data
|
|
537
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/SwapVM.sol#L84
|
|
538
|
+
*/
|
|
539
|
+
static encodeQuoteCallData(args) {
|
|
540
|
+
const result = (0, viem.encodeFunctionData)({
|
|
541
|
+
abi: SWAP_VM_ABI,
|
|
542
|
+
functionName: "quote",
|
|
543
|
+
args: [
|
|
544
|
+
args.order.build(),
|
|
545
|
+
args.tokenIn.toString(),
|
|
546
|
+
args.tokenOut.toString(),
|
|
547
|
+
args.amount,
|
|
548
|
+
args.takerTraits.encode().toString()
|
|
549
|
+
]
|
|
550
|
+
});
|
|
551
|
+
return new __1inch_sdk_core.HexString(result);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Encode `hashOrder` function call data
|
|
555
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/SwapVM.sol#L70
|
|
556
|
+
*/
|
|
557
|
+
static encodeHashOrderCallData(order) {
|
|
558
|
+
const result = (0, viem.encodeFunctionData)({
|
|
559
|
+
abi: SWAP_VM_ABI,
|
|
560
|
+
functionName: "hash",
|
|
561
|
+
args: [order.build()]
|
|
562
|
+
});
|
|
563
|
+
return new __1inch_sdk_core.HexString(result);
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Encode swap function call data
|
|
567
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/SwapVM.sol#L124
|
|
568
|
+
*/
|
|
569
|
+
static encodeSwapCallData(args) {
|
|
570
|
+
const result = (0, viem.encodeFunctionData)({
|
|
571
|
+
abi: SWAP_VM_ABI,
|
|
572
|
+
functionName: "swap",
|
|
573
|
+
args: [
|
|
574
|
+
args.order.build(),
|
|
575
|
+
args.tokenIn.toString(),
|
|
576
|
+
args.tokenOut.toString(),
|
|
577
|
+
args.amount,
|
|
578
|
+
args.takerTraits.encode().toString()
|
|
579
|
+
]
|
|
580
|
+
});
|
|
581
|
+
return new __1inch_sdk_core.HexString(result);
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Build quote transaction
|
|
585
|
+
*/
|
|
586
|
+
static buildQuoteTx(contractAddress, args) {
|
|
587
|
+
return {
|
|
588
|
+
to: contractAddress.toString(),
|
|
589
|
+
data: this.encodeQuoteCallData(args).toString(),
|
|
590
|
+
value: 0n
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Build swap transaction
|
|
595
|
+
*/
|
|
596
|
+
static buildSwapTx(contractAddress, args) {
|
|
597
|
+
return {
|
|
598
|
+
to: contractAddress.toString(),
|
|
599
|
+
data: this.encodeSwapCallData(args).toString(),
|
|
600
|
+
value: 0n
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
static buildHashOrderTx(contractAddress, order) {
|
|
604
|
+
return {
|
|
605
|
+
to: contractAddress.toString(),
|
|
606
|
+
data: this.encodeHashOrderCallData(order).toString(),
|
|
607
|
+
value: 0n
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
swap(args) {
|
|
611
|
+
return SwapVMContract.buildSwapTx(this.address, args);
|
|
612
|
+
}
|
|
613
|
+
quote(args) {
|
|
614
|
+
return SwapVMContract.buildQuoteTx(this.address, args);
|
|
615
|
+
}
|
|
616
|
+
hashOrder(order) {
|
|
617
|
+
return SwapVMContract.buildHashOrderTx(this.address, order);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/swap-vm-contract/constants.ts
|
|
623
|
+
/**
|
|
624
|
+
* AquaSwapVMRouter contract addresses by chain ID
|
|
625
|
+
* These addresses supports only AQUA instructions set
|
|
626
|
+
*
|
|
627
|
+
* Deployed with next params
|
|
628
|
+
* - name = `AquaSwapVMRouter`
|
|
629
|
+
* - version = `1.0.0`
|
|
630
|
+
*
|
|
631
|
+
* @see https://github.com/1inch/swap-vm/blob/8cc4c467374959af9efdb6e2b67d32d3c1083e1e/src/routers/AquaSwapVMRouter.sol#L11
|
|
632
|
+
* @see "../swap-vm/programs/aqua-program-builder"
|
|
633
|
+
*/
|
|
634
|
+
const AQUA_SWAP_VM_CONTRACT_ADDRESSES = {
|
|
635
|
+
[__1inch_sdk_core.NetworkEnum.ETHEREUM]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
636
|
+
[__1inch_sdk_core.NetworkEnum.BINANCE]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
637
|
+
[__1inch_sdk_core.NetworkEnum.POLYGON]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
638
|
+
[__1inch_sdk_core.NetworkEnum.ARBITRUM]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
639
|
+
[__1inch_sdk_core.NetworkEnum.AVALANCHE]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
640
|
+
[__1inch_sdk_core.NetworkEnum.GNOSIS]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
641
|
+
[__1inch_sdk_core.NetworkEnum.COINBASE]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
642
|
+
[__1inch_sdk_core.NetworkEnum.OPTIMISM]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
643
|
+
[__1inch_sdk_core.NetworkEnum.ZKSYNC]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
644
|
+
[__1inch_sdk_core.NetworkEnum.LINEA]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
645
|
+
[__1inch_sdk_core.NetworkEnum.UNICHAIN]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f"),
|
|
646
|
+
[__1inch_sdk_core.NetworkEnum.SONIC]: new __1inch_sdk_core.Address("0x8fdd04dbf6111437b44bbca99c28882434e0958f")
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
//#endregion
|
|
650
|
+
//#region src/swap-vm-contract/events/swapped-event.ts
|
|
651
|
+
var SwappedEvent = class SwappedEvent {
|
|
652
|
+
static TOPIC = new __1inch_sdk_core.HexString("0x54bc5c027d15d7aa8ae083f994ab4411d2f223291672ecd3a344f3d92dcaf8b2");
|
|
653
|
+
constructor(orderHash, maker, taker, tokenIn, tokenOut, amountIn, amountOut) {
|
|
654
|
+
this.orderHash = orderHash;
|
|
655
|
+
this.maker = maker;
|
|
656
|
+
this.taker = taker;
|
|
657
|
+
this.tokenIn = tokenIn;
|
|
658
|
+
this.tokenOut = tokenOut;
|
|
659
|
+
this.amountIn = amountIn;
|
|
660
|
+
this.amountOut = amountOut;
|
|
661
|
+
}
|
|
662
|
+
static new(data) {
|
|
663
|
+
return new SwappedEvent(data.orderHash, data.maker, data.taker, data.tokenIn, data.tokenOut, data.amountIn, data.amountOut);
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Creates a SwappedEvent
|
|
667
|
+
* @throws Error if the log data is invalid or doesn't match the expected event structure
|
|
668
|
+
*/
|
|
669
|
+
static fromLog(log) {
|
|
670
|
+
const decoded = (0, viem.decodeEventLog)({
|
|
671
|
+
abi: SWAP_VM_ABI,
|
|
672
|
+
data: log.data,
|
|
673
|
+
topics: log.topics,
|
|
674
|
+
eventName: "Swapped"
|
|
675
|
+
});
|
|
676
|
+
const { orderHash, maker, taker, tokenIn, tokenOut, amountIn, amountOut } = decoded.args;
|
|
677
|
+
return new SwappedEvent(new __1inch_sdk_core.HexString(orderHash), new __1inch_sdk_core.Address(maker), new __1inch_sdk_core.Address(taker), new __1inch_sdk_core.Address(tokenIn), new __1inch_sdk_core.Address(tokenOut), amountIn, amountOut);
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
//#endregion
|
|
682
|
+
//#region src/swap-vm/maker-traits.ts
|
|
683
|
+
/**
|
|
684
|
+
* Maker-side order configuration packed into a single `uint256` and an optional hooks data blob.
|
|
685
|
+
*
|
|
686
|
+
* This class mirrors the on-chain `MakerTraits` bit layout and encoding used by the SwapVM
|
|
687
|
+
* contracts. It is responsible for:
|
|
688
|
+
*
|
|
689
|
+
* - maker preferences (unwrap WETH, allow zero amount in, Aqua vs signature)
|
|
690
|
+
* - selecting an optional custom receiver
|
|
691
|
+
* - wiring pre/post transfer hooks and their optional targets/payloads
|
|
692
|
+
*
|
|
693
|
+
* The ABI-level representation is:
|
|
694
|
+
* - `traits` – a `uint256` where:
|
|
695
|
+
* - high bits 245–255 store boolean flags
|
|
696
|
+
* - bits 160–223 store cumulative offsets for hook data slices (4 × `uint16`)
|
|
697
|
+
* - bits 0–159 store the receiver address (0 means "maker")
|
|
698
|
+
* - `hooksData` – concatenation of hook payloads in the order:
|
|
699
|
+
* `preTransferIn`, `postTransferIn`, `preTransferOut`, `postTransferOut`
|
|
700
|
+
*/
|
|
701
|
+
var MakerTraits = class MakerTraits {
|
|
702
|
+
static HOOKS = [
|
|
703
|
+
"preTransferInHook",
|
|
704
|
+
"postTransferInHook",
|
|
705
|
+
"preTransferOutHook",
|
|
706
|
+
"postTransferOutHook"
|
|
707
|
+
];
|
|
708
|
+
static SHOULD_UNWRAP_BIT_FLAG = 255n;
|
|
709
|
+
static USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG = 254n;
|
|
710
|
+
static ALLOW_ZERO_AMOUNT_IN = 253n;
|
|
711
|
+
static HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG = 252n;
|
|
712
|
+
static HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG = 251n;
|
|
713
|
+
static HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG = 250n;
|
|
714
|
+
static HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG = 249n;
|
|
715
|
+
static PRE_TRANSFER_IN_HOOK_HAS_TARGET = 248n;
|
|
716
|
+
static POST_TRANSFER_IN_HOOK_HAS_TARGET = 247n;
|
|
717
|
+
static PRE_TRANSFER_OUT_HOOK_HAS_TARGET = 246n;
|
|
718
|
+
static POST_TRANSFER_OUT_HOOK_HAS_TARGET = 245n;
|
|
719
|
+
static CUSTOM_RECEIVER_MASK = new __1inch_byte_utils.BitMask(0n, 160n);
|
|
720
|
+
static HOOKS_DATA_OFFSETS_MASK = new __1inch_byte_utils.BitMask(160n, 224n);
|
|
721
|
+
constructor(shouldUnwrap, useAquaInsteadOfSignature, allowZeroAmountIn, customReceiver, preTransferInHook, postTransferInHook, preTransferOutHook, postTransferOutHook) {
|
|
722
|
+
this.shouldUnwrap = shouldUnwrap;
|
|
723
|
+
this.useAquaInsteadOfSignature = useAquaInsteadOfSignature;
|
|
724
|
+
this.allowZeroAmountIn = allowZeroAmountIn;
|
|
725
|
+
this.customReceiver = customReceiver;
|
|
726
|
+
this.preTransferInHook = preTransferInHook;
|
|
727
|
+
this.postTransferInHook = postTransferInHook;
|
|
728
|
+
this.preTransferOutHook = preTransferOutHook;
|
|
729
|
+
this.postTransferOutHook = postTransferOutHook;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Construct traits from a plain data object.
|
|
733
|
+
*/
|
|
734
|
+
static new(data) {
|
|
735
|
+
return new MakerTraits(data.shouldUnwrap, data.useAquaInsteadOfSignature, data.allowZeroAmountIn, data.customReceiver, data.preTransferInHook, data.postTransferInHook, data.preTransferOutHook, data.postTransferOutHook);
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Create traits with library defaults that match the on-chain SwapVM expectations:
|
|
739
|
+
* - `useAquaInsteadOfSignature` = `true`
|
|
740
|
+
* - `shouldUnwrap` = `false`
|
|
741
|
+
* - `allowZeroAmountIn` = `false`
|
|
742
|
+
* - no receiver or hooks configured.
|
|
743
|
+
*/
|
|
744
|
+
static default() {
|
|
745
|
+
return MakerTraits.new({
|
|
746
|
+
useAquaInsteadOfSignature: true,
|
|
747
|
+
allowZeroAmountIn: false,
|
|
748
|
+
shouldUnwrap: false
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Decode ABI-level representation into a `MakerTraits` instance.
|
|
753
|
+
*
|
|
754
|
+
* @param traits Packed `uint256` bitfield as produced by {@link encode}.
|
|
755
|
+
* @param hooksData Concatenated hooks payloads in the format expected by SwapVM
|
|
756
|
+
* contracts (may be `HexString.EMPTY` when no hooks are present).
|
|
757
|
+
*
|
|
758
|
+
* Both arguments are typically obtained from contract storage / ABI and must
|
|
759
|
+
* follow the bit layout described in the class-level documentation.
|
|
760
|
+
*/
|
|
761
|
+
static decode(traits, hooksData = __1inch_sdk_core.HexString.EMPTY) {
|
|
762
|
+
const traitsBN = new __1inch_byte_utils.BN(traits);
|
|
763
|
+
const shouldUnwrap = traitsBN.getBit(MakerTraits.SHOULD_UNWRAP_BIT_FLAG);
|
|
764
|
+
const useAquaInsteadOfSignature = traitsBN.getBit(MakerTraits.USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG);
|
|
765
|
+
const allowZeroAmountIn = traitsBN.getBit(MakerTraits.ALLOW_ZERO_AMOUNT_IN);
|
|
766
|
+
const customReceiver = __1inch_sdk_core.Address.fromBigInt(traitsBN.getMask(MakerTraits.CUSTOM_RECEIVER_MASK).value);
|
|
767
|
+
const hooksDataOffsets = traitsBN.getMask(MakerTraits.HOOKS_DATA_OFFSETS_MASK).value;
|
|
768
|
+
const hasPreTransferInHook = Boolean(traitsBN.getBit(MakerTraits.HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG));
|
|
769
|
+
const hasPreTransferInHookTarget = Boolean(traitsBN.getBit(MakerTraits.PRE_TRANSFER_IN_HOOK_HAS_TARGET));
|
|
770
|
+
const preTransferInHook = parseHook(hooksData, hasPreTransferInHook, hasPreTransferInHookTarget, hooksDataOffsets, 0);
|
|
771
|
+
const hasPostTransferInHook = Boolean(traitsBN.getBit(MakerTraits.HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG));
|
|
772
|
+
const hasPostTransferInHookTarget = Boolean(traitsBN.getBit(MakerTraits.POST_TRANSFER_IN_HOOK_HAS_TARGET));
|
|
773
|
+
const postTransferInHook = parseHook(hooksData, hasPostTransferInHook, hasPostTransferInHookTarget, hooksDataOffsets, 1);
|
|
774
|
+
const hasPreTransferOutHook = Boolean(traitsBN.getBit(MakerTraits.HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG));
|
|
775
|
+
const hasPreTransferOutHookTarget = Boolean(traitsBN.getBit(MakerTraits.PRE_TRANSFER_OUT_HOOK_HAS_TARGET));
|
|
776
|
+
const preTransferOutHook = parseHook(hooksData, hasPreTransferOutHook, hasPreTransferOutHookTarget, hooksDataOffsets, 2);
|
|
777
|
+
const hasPostTransferOutHook = Boolean(traitsBN.getBit(MakerTraits.HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG));
|
|
778
|
+
const hasPostTransferOutHookTarget = Boolean(traitsBN.getBit(MakerTraits.POST_TRANSFER_OUT_HOOK_HAS_TARGET));
|
|
779
|
+
const postTransferOutHook = parseHook(hooksData, hasPostTransferOutHook, hasPostTransferOutHookTarget, hooksDataOffsets, 3);
|
|
780
|
+
return MakerTraits.new({
|
|
781
|
+
useAquaInsteadOfSignature: Boolean(useAquaInsteadOfSignature),
|
|
782
|
+
allowZeroAmountIn: Boolean(allowZeroAmountIn),
|
|
783
|
+
shouldUnwrap: Boolean(shouldUnwrap),
|
|
784
|
+
customReceiver: customReceiver.isZero() ? void 0 : customReceiver,
|
|
785
|
+
preTransferInHook,
|
|
786
|
+
postTransferInHook,
|
|
787
|
+
preTransferOutHook,
|
|
788
|
+
postTransferOutHook
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
static hooksDataEndsAtByte(traits) {
|
|
792
|
+
const bn = new __1inch_byte_utils.BN(traits);
|
|
793
|
+
const offsets = bn.getMask(MakerTraits.HOOKS_DATA_OFFSETS_MASK).value;
|
|
794
|
+
const dataEndAt = Number(offsets >> 16n * BigInt(MakerTraits.HOOKS.length - 1) & 0xffffn);
|
|
795
|
+
return dataEndAt;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Mutate the traits instance in-place with a partial update and return it.
|
|
799
|
+
*
|
|
800
|
+
* This is primarily used for fluent-style construction in tests and examples, e.g.:
|
|
801
|
+
*
|
|
802
|
+
* `MakerTraits.default().with({ shouldUnwrap: true })`
|
|
803
|
+
*
|
|
804
|
+
* Only fields present in `data` are updated; flags, receiver, and hooks can be
|
|
805
|
+
* changed independently.
|
|
806
|
+
*/
|
|
807
|
+
with(data) {
|
|
808
|
+
Object.assign(this, data);
|
|
809
|
+
return this;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Encode traits into the ABI format expected by SwapVM contracts.
|
|
813
|
+
*
|
|
814
|
+
* @param maker - Maker address for this order. This parameter is required only
|
|
815
|
+
* for gas/size optimisation; if omitted, any non-zero hook `target`
|
|
816
|
+
* is treated as an explicit target.
|
|
817
|
+
*
|
|
818
|
+
* @returns An object containing:
|
|
819
|
+
* - `traits` - Packed `uint256` bitfield with flags, receiver and offsets
|
|
820
|
+
* - `hooksData` - Concatenation of hook segments for all configured hooks
|
|
821
|
+
*
|
|
822
|
+
* ## Bit Layout of `traits` (uint256)
|
|
823
|
+
*
|
|
824
|
+
* ```
|
|
825
|
+
* 255 0
|
|
826
|
+
* +------------+----------------------------+------------------+
|
|
827
|
+
* | Flags | Hook Offsets (4×uint16) | Receiver Address |
|
|
828
|
+
* | [255-245] | [223-160] | [159-0] |
|
|
829
|
+
* +------------+----------------------------+------------------+
|
|
830
|
+
* ```
|
|
831
|
+
*
|
|
832
|
+
* ## Flags (by bit index)
|
|
833
|
+
*
|
|
834
|
+
* | Bit | Flag Name |
|
|
835
|
+
* |-----|------------------------------------------|
|
|
836
|
+
* | 255 | SHOULD_UNWRAP_BIT_FLAG |
|
|
837
|
+
* | 254 | USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG |
|
|
838
|
+
* | 253 | ALLOW_ZERO_AMOUNT_IN |
|
|
839
|
+
* | 252 | HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG |
|
|
840
|
+
* | 251 | HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG |
|
|
841
|
+
* | 250 | HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG |
|
|
842
|
+
* | 249 | HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG |
|
|
843
|
+
* | 248 | PRE_TRANSFER_IN_HOOK_HAS_TARGET |
|
|
844
|
+
* | 247 | POST_TRANSFER_IN_HOOK_HAS_TARGET |
|
|
845
|
+
* | 246 | PRE_TRANSFER_OUT_HOOK_HAS_TARGET |
|
|
846
|
+
* | 245 | POST_TRANSFER_OUT_HOOK_HAS_TARGET |
|
|
847
|
+
*/
|
|
848
|
+
encode(maker) {
|
|
849
|
+
let traits = new __1inch_byte_utils.BN(0n);
|
|
850
|
+
traits = traits.setBit(MakerTraits.SHOULD_UNWRAP_BIT_FLAG, this.shouldUnwrap);
|
|
851
|
+
traits = traits.setBit(MakerTraits.USE_AQUA_INSTEAD_OF_SIGNATURE_BIT_FLAG, this.useAquaInsteadOfSignature);
|
|
852
|
+
traits = traits.setBit(MakerTraits.ALLOW_ZERO_AMOUNT_IN, this.allowZeroAmountIn);
|
|
853
|
+
traits = traits.setBit(MakerTraits.HAS_PRE_TRANSFER_IN_HOOK_BIT_FLAG, this.preTransferInHook !== void 0);
|
|
854
|
+
traits = traits.setBit(MakerTraits.HAS_POST_TRANSFER_IN_HOOK_BIT_FLAG, this.postTransferInHook !== void 0);
|
|
855
|
+
traits = traits.setBit(MakerTraits.HAS_PRE_TRANSFER_OUT_HOOK_BIT_FLAG, this.preTransferOutHook !== void 0);
|
|
856
|
+
traits = traits.setBit(MakerTraits.HAS_POST_TRANSFER_OUT_HOOK_BIT_FLAG, this.postTransferOutHook !== void 0);
|
|
857
|
+
traits = traits.setBit(MakerTraits.PRE_TRANSFER_IN_HOOK_HAS_TARGET, this.hasTargetForHook("preTransferInHook", maker));
|
|
858
|
+
traits = traits.setBit(MakerTraits.POST_TRANSFER_IN_HOOK_HAS_TARGET, this.hasTargetForHook("postTransferInHook", maker));
|
|
859
|
+
traits = traits.setBit(MakerTraits.PRE_TRANSFER_OUT_HOOK_HAS_TARGET, this.hasTargetForHook("preTransferOutHook", maker));
|
|
860
|
+
traits = traits.setBit(MakerTraits.POST_TRANSFER_OUT_HOOK_HAS_TARGET, this.hasTargetForHook("postTransferOutHook", maker));
|
|
861
|
+
traits = traits.setMask(MakerTraits.CUSTOM_RECEIVER_MASK, BigInt(this.customReceiver?.toString() || 0n));
|
|
862
|
+
const { data, offsets } = MakerTraits.HOOKS.reduce((acc, hookName, i) => {
|
|
863
|
+
const hook = this[hookName];
|
|
864
|
+
const hasTarget = this.hasTargetForHook(hookName);
|
|
865
|
+
const encoded = hook && hasTarget ? hook.encode() : hook?.data || __1inch_sdk_core.HexString.EMPTY;
|
|
866
|
+
acc.sum += BigInt(encoded.bytesCount());
|
|
867
|
+
acc.offsets += acc.sum << 16n * BigInt(i);
|
|
868
|
+
acc.data = acc.data.concat(encoded);
|
|
869
|
+
return acc;
|
|
870
|
+
}, {
|
|
871
|
+
data: __1inch_sdk_core.HexString.EMPTY,
|
|
872
|
+
offsets: 0n,
|
|
873
|
+
sum: 0n
|
|
874
|
+
});
|
|
875
|
+
traits = traits.setMask(MakerTraits.HOOKS_DATA_OFFSETS_MASK, offsets);
|
|
876
|
+
return {
|
|
877
|
+
traits: traits.value,
|
|
878
|
+
hooksData: data
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
hasTargetForHook(hookName, maker = __1inch_sdk_core.Address.ZERO_ADDRESS) {
|
|
882
|
+
const hook = this[hookName];
|
|
883
|
+
if (!hook) return false;
|
|
884
|
+
return !(hook.target.isZero() || hook.target.equal(maker));
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
function parseHook(fullHookData, hasHook, hasHookTarget, offsets, idx) {
|
|
888
|
+
if (!hasHook) return void 0;
|
|
889
|
+
const startDataIdx = idx === 0 ? 0 : Number(offsets >> 16n * BigInt(idx - 1) & 0xffffn);
|
|
890
|
+
const endDataIdx = Number(offsets >> 16n * BigInt(idx) & 0xffffn);
|
|
891
|
+
const hookData = fullHookData.sliceBytes(startDataIdx, endDataIdx);
|
|
892
|
+
if (!hasHookTarget) return new __1inch_sdk_core.Interaction(__1inch_sdk_core.Address.ZERO_ADDRESS, hookData);
|
|
893
|
+
return __1inch_sdk_core.Interaction.decode(hookData);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
//#endregion
|
|
897
|
+
//#region src/swap-vm/taker-traits.ts
|
|
898
|
+
/**
|
|
899
|
+
* TakerTraits encodes taker-specific parameters and flags for swap execution.
|
|
900
|
+
* It defines how the taker wants the swap to be executed, including thresholds,
|
|
901
|
+
* callbacks, hooks, and other execution parameters.
|
|
902
|
+
*/
|
|
903
|
+
var TakerTraits = class TakerTraits {
|
|
904
|
+
static IS_EXACT_IN_BIT_FLAG = 0n;
|
|
905
|
+
static SHOULD_UNWRAP_BIT_FLAG = 1n;
|
|
906
|
+
static HAS_PRE_TRANSFER_IN_CALLBACK_BIT_FLAG = 2n;
|
|
907
|
+
static HAS_PRE_TRANSFER_OUT_CALLBACK_BIT_FLAG = 3n;
|
|
908
|
+
static IS_STRICT_THRESHOLD_BIT_FLAG = 4n;
|
|
909
|
+
static IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG = 5n;
|
|
910
|
+
static USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG = 6n;
|
|
911
|
+
constructor(exactIn, shouldUnwrap, preTransferInCallbackEnabled, preTransferOutCallbackEnabled, strictThreshold, firstTransferFromTaker, useTransferFromAndAquaPush, threshold = 0n, customReceiver = __1inch_sdk_core.Address.ZERO_ADDRESS, preTransferInHookData = __1inch_sdk_core.HexString.EMPTY, postTransferInHookData = __1inch_sdk_core.HexString.EMPTY, preTransferOutHookData = __1inch_sdk_core.HexString.EMPTY, postTransferOutHookData = __1inch_sdk_core.HexString.EMPTY, preTransferInCallbackData = __1inch_sdk_core.HexString.EMPTY, preTransferOutCallbackData = __1inch_sdk_core.HexString.EMPTY, instructionsArgs = __1inch_sdk_core.HexString.EMPTY, signature = __1inch_sdk_core.HexString.EMPTY) {
|
|
912
|
+
this.exactIn = exactIn;
|
|
913
|
+
this.shouldUnwrap = shouldUnwrap;
|
|
914
|
+
this.preTransferInCallbackEnabled = preTransferInCallbackEnabled;
|
|
915
|
+
this.preTransferOutCallbackEnabled = preTransferOutCallbackEnabled;
|
|
916
|
+
this.strictThreshold = strictThreshold;
|
|
917
|
+
this.firstTransferFromTaker = firstTransferFromTaker;
|
|
918
|
+
this.useTransferFromAndAquaPush = useTransferFromAndAquaPush;
|
|
919
|
+
this.threshold = threshold;
|
|
920
|
+
this.customReceiver = customReceiver;
|
|
921
|
+
this.preTransferInHookData = preTransferInHookData;
|
|
922
|
+
this.postTransferInHookData = postTransferInHookData;
|
|
923
|
+
this.preTransferOutHookData = preTransferOutHookData;
|
|
924
|
+
this.postTransferOutHookData = postTransferOutHookData;
|
|
925
|
+
this.preTransferInCallbackData = preTransferInCallbackData;
|
|
926
|
+
this.preTransferOutCallbackData = preTransferOutCallbackData;
|
|
927
|
+
this.instructionsArgs = instructionsArgs;
|
|
928
|
+
this.signature = signature;
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Creates a new TakerTraits instance with the specified data.
|
|
932
|
+
* Provides default values for unspecified fields.
|
|
933
|
+
*/
|
|
934
|
+
static new(data = {}) {
|
|
935
|
+
return new TakerTraits(data.exactIn ?? true, data.shouldUnwrap ?? false, data.preTransferInCallbackEnabled ?? false, data.preTransferOutCallbackEnabled ?? false, data.strictThreshold ?? false, data.firstTransferFromTaker ?? false, data.useTransferFromAndAquaPush ?? true, data.threshold, data.customReceiver, data.preTransferInHookData, data.postTransferInHookData, data.preTransferOutHookData, data.postTransferOutHookData, data.preTransferInCallbackData, data.preTransferOutCallbackData, data.instructionsArgs, data.signature);
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Creates a default TakerTraits instance with standard settings.
|
|
939
|
+
* - exactIn mode
|
|
940
|
+
* - No unwrapping
|
|
941
|
+
* - No callbacks
|
|
942
|
+
* - No custom receiver
|
|
943
|
+
* - transferFromAndAquaPush enabled
|
|
944
|
+
*/
|
|
945
|
+
static default() {
|
|
946
|
+
return TakerTraits.new({
|
|
947
|
+
exactIn: true,
|
|
948
|
+
shouldUnwrap: false,
|
|
949
|
+
preTransferInCallbackEnabled: false,
|
|
950
|
+
preTransferOutCallbackEnabled: false,
|
|
951
|
+
strictThreshold: false,
|
|
952
|
+
firstTransferFromTaker: false,
|
|
953
|
+
useTransferFromAndAquaPush: true,
|
|
954
|
+
threshold: 0n,
|
|
955
|
+
customReceiver: __1inch_sdk_core.Address.ZERO_ADDRESS,
|
|
956
|
+
preTransferInHookData: __1inch_sdk_core.HexString.EMPTY,
|
|
957
|
+
postTransferInHookData: __1inch_sdk_core.HexString.EMPTY,
|
|
958
|
+
preTransferOutHookData: __1inch_sdk_core.HexString.EMPTY,
|
|
959
|
+
postTransferOutHookData: __1inch_sdk_core.HexString.EMPTY,
|
|
960
|
+
preTransferInCallbackData: __1inch_sdk_core.HexString.EMPTY,
|
|
961
|
+
preTransferOutCallbackData: __1inch_sdk_core.HexString.EMPTY,
|
|
962
|
+
instructionsArgs: __1inch_sdk_core.HexString.EMPTY,
|
|
963
|
+
signature: __1inch_sdk_core.HexString.EMPTY
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Decodes a packed TakerTraits from a hex string.
|
|
968
|
+
* The packed format consists of:
|
|
969
|
+
* - 18 bytes: 9 uint16 offsets for data sections
|
|
970
|
+
* - 2 bytes: uint16 flags
|
|
971
|
+
* - Variable: data sections (threshold, to, hook data, callback data, etc.)
|
|
972
|
+
* - Variable: signature
|
|
973
|
+
*/
|
|
974
|
+
static decode(packed) {
|
|
975
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(packed.toString());
|
|
976
|
+
const offsets = Array.from({ length: 9 }, () => Number(iter.nextUint16())).reverse();
|
|
977
|
+
const flags = new __1inch_byte_utils.BN(iter.nextUint16());
|
|
978
|
+
const dataStr = (0, __1inch_byte_utils.trim0x)(packed.toString()).slice(40);
|
|
979
|
+
const sections = [];
|
|
980
|
+
offsets.forEach((offset, i) => {
|
|
981
|
+
const start = i === 0 ? 0 : offsets[i - 1];
|
|
982
|
+
sections.push(offset > start ? dataStr.slice(start * 2, offset * 2) : "");
|
|
983
|
+
});
|
|
984
|
+
const lastOffset = offsets[offsets.length - 1];
|
|
985
|
+
const signature = dataStr.length > lastOffset * 2 ? dataStr.slice(lastOffset * 2) : "";
|
|
986
|
+
const [threshold, to, preTransferInHookData, postTransferInHookData, preTransferOutHookData, postTransferOutHookData, preTransferInCallbackData, preTransferOutCallbackData, instructionsArgs] = sections;
|
|
987
|
+
return TakerTraits.new({
|
|
988
|
+
exactIn: Boolean(flags.getBit(TakerTraits.IS_EXACT_IN_BIT_FLAG)),
|
|
989
|
+
shouldUnwrap: Boolean(flags.getBit(TakerTraits.SHOULD_UNWRAP_BIT_FLAG)),
|
|
990
|
+
preTransferInCallbackEnabled: Boolean(flags.getBit(TakerTraits.HAS_PRE_TRANSFER_IN_CALLBACK_BIT_FLAG)),
|
|
991
|
+
preTransferOutCallbackEnabled: Boolean(flags.getBit(TakerTraits.HAS_PRE_TRANSFER_OUT_CALLBACK_BIT_FLAG)),
|
|
992
|
+
strictThreshold: Boolean(flags.getBit(TakerTraits.IS_STRICT_THRESHOLD_BIT_FLAG)),
|
|
993
|
+
firstTransferFromTaker: Boolean(flags.getBit(TakerTraits.IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG)),
|
|
994
|
+
useTransferFromAndAquaPush: Boolean(flags.getBit(TakerTraits.USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG)),
|
|
995
|
+
threshold: threshold ? BigInt((0, __1inch_byte_utils.add0x)(threshold)) : 0n,
|
|
996
|
+
customReceiver: to ? new __1inch_sdk_core.Address((0, __1inch_byte_utils.add0x)(to)) : __1inch_sdk_core.Address.ZERO_ADDRESS,
|
|
997
|
+
preTransferInHookData: preTransferInHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(preTransferInHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
998
|
+
postTransferInHookData: postTransferInHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(postTransferInHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
999
|
+
preTransferOutHookData: preTransferOutHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(preTransferOutHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
1000
|
+
postTransferOutHookData: postTransferOutHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(postTransferOutHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
1001
|
+
preTransferInCallbackData: preTransferInCallbackData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(preTransferInCallbackData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
1002
|
+
preTransferOutCallbackData: preTransferOutCallbackData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(preTransferOutCallbackData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
1003
|
+
instructionsArgs: instructionsArgs ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(instructionsArgs)) : __1inch_sdk_core.HexString.EMPTY,
|
|
1004
|
+
signature: signature ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(signature)) : __1inch_sdk_core.HexString.EMPTY
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Creates a new instance with updated fields.
|
|
1009
|
+
* Useful for creating modified versions of existing TakerTraits.
|
|
1010
|
+
*/
|
|
1011
|
+
with(data) {
|
|
1012
|
+
Object.assign(this, data);
|
|
1013
|
+
return this;
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Encodes the TakerTraits into a packed hex string format.
|
|
1017
|
+
* The encoding includes offsets, flags, data sections, and signature.
|
|
1018
|
+
* Callback flags are automatically set based on callback data presence.
|
|
1019
|
+
*/
|
|
1020
|
+
encode() {
|
|
1021
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1022
|
+
const dataFields = [
|
|
1023
|
+
this.threshold > 0n ? new __1inch_sdk_core.HexString("0x" + this.threshold.toString(16).padStart(64, "0")) : __1inch_sdk_core.HexString.EMPTY,
|
|
1024
|
+
!this.customReceiver.isZero() ? new __1inch_sdk_core.HexString(this.customReceiver.toString()) : __1inch_sdk_core.HexString.EMPTY,
|
|
1025
|
+
this.preTransferInHookData,
|
|
1026
|
+
this.postTransferInHookData,
|
|
1027
|
+
this.preTransferOutHookData,
|
|
1028
|
+
this.postTransferOutHookData,
|
|
1029
|
+
this.preTransferInCallbackData,
|
|
1030
|
+
this.preTransferOutCallbackData,
|
|
1031
|
+
this.instructionsArgs
|
|
1032
|
+
];
|
|
1033
|
+
const { offsets, data } = dataFields.reduce((acc, field) => {
|
|
1034
|
+
const length = field.bytesCount();
|
|
1035
|
+
acc.sum += length;
|
|
1036
|
+
acc.offsets.push(acc.sum);
|
|
1037
|
+
acc.data.push(field.toString().slice(2));
|
|
1038
|
+
return acc;
|
|
1039
|
+
}, {
|
|
1040
|
+
sum: 0,
|
|
1041
|
+
offsets: [],
|
|
1042
|
+
data: []
|
|
1043
|
+
});
|
|
1044
|
+
offsets.reverse().forEach((offset) => builder.addUint16(BigInt(offset)));
|
|
1045
|
+
let flags = new __1inch_byte_utils.BN(0n);
|
|
1046
|
+
flags = flags.setBit(TakerTraits.IS_EXACT_IN_BIT_FLAG, this.exactIn);
|
|
1047
|
+
flags = flags.setBit(TakerTraits.SHOULD_UNWRAP_BIT_FLAG, this.shouldUnwrap);
|
|
1048
|
+
flags = flags.setBit(TakerTraits.HAS_PRE_TRANSFER_IN_CALLBACK_BIT_FLAG, !this.preTransferInCallbackData.isEmpty());
|
|
1049
|
+
flags = flags.setBit(TakerTraits.HAS_PRE_TRANSFER_OUT_CALLBACK_BIT_FLAG, !this.preTransferOutCallbackData.isEmpty());
|
|
1050
|
+
flags = flags.setBit(TakerTraits.IS_STRICT_THRESHOLD_BIT_FLAG, this.strictThreshold);
|
|
1051
|
+
flags = flags.setBit(TakerTraits.IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG, this.firstTransferFromTaker);
|
|
1052
|
+
flags = flags.setBit(TakerTraits.USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG, this.useTransferFromAndAquaPush);
|
|
1053
|
+
builder.addUint16(flags.value);
|
|
1054
|
+
const allData = data.join("") + this.signature.toString().slice(2);
|
|
1055
|
+
if (allData) builder.addBytes("0x" + allData);
|
|
1056
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Validates the swap amounts against the threshold settings.
|
|
1060
|
+
* @param amountIn - The input amount of the swap
|
|
1061
|
+
* @param amountOut - The output amount of the swap
|
|
1062
|
+
* @throws Error if the amounts don't meet the threshold requirements
|
|
1063
|
+
*/
|
|
1064
|
+
validate(amountIn, amountOut) {
|
|
1065
|
+
if (this.threshold === 0n) return;
|
|
1066
|
+
const threshold = this.threshold;
|
|
1067
|
+
if (this.strictThreshold) {
|
|
1068
|
+
const actual = this.exactIn ? amountOut : amountIn;
|
|
1069
|
+
if (actual !== threshold) throw new Error(`TakerTraitsNonExactThresholdAmount: ${this.exactIn ? "amountOut" : "amountIn"} ${actual} != threshold ${threshold}`);
|
|
1070
|
+
} else if (this.exactIn) {
|
|
1071
|
+
if (amountOut < threshold) throw new Error(`TakerTraitsInsufficientMinOutputAmount: amountOut ${amountOut} < threshold ${threshold}`);
|
|
1072
|
+
} else if (amountIn > threshold) throw new Error(`TakerTraitsExceedingMaxInputAmount: amountIn ${amountIn} > threshold ${threshold}`);
|
|
1073
|
+
}
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
//#endregion
|
|
1077
|
+
//#region src/swap-vm/programs/swap-vm-program.ts
|
|
1078
|
+
/**
|
|
1079
|
+
* Represents encoded SwapVM program bytecode
|
|
1080
|
+
**/
|
|
1081
|
+
var SwapVmProgram = class extends __1inch_sdk_core.HexString {};
|
|
1082
|
+
|
|
1083
|
+
//#endregion
|
|
1084
|
+
//#region src/swap-vm/instructions/instruction.ts
|
|
1085
|
+
var Instruction = class {
|
|
1086
|
+
constructor(opcode, args) {
|
|
1087
|
+
this.opcode = opcode;
|
|
1088
|
+
this.args = args;
|
|
1089
|
+
}
|
|
1090
|
+
toJSON() {
|
|
1091
|
+
return {
|
|
1092
|
+
opcode: this.opcode.id.toString(),
|
|
1093
|
+
args: this.args.toJSON()
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
//#endregion
|
|
1099
|
+
//#region src/swap-vm/instructions/opcode.ts
|
|
1100
|
+
var Opcode = class {
|
|
1101
|
+
constructor(id, coder) {
|
|
1102
|
+
this.id = id;
|
|
1103
|
+
this.coder = coder;
|
|
1104
|
+
}
|
|
1105
|
+
argsCoder() {
|
|
1106
|
+
return this.coder;
|
|
1107
|
+
}
|
|
1108
|
+
createIx(args) {
|
|
1109
|
+
return new Instruction(this, args);
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
//#endregion
|
|
1114
|
+
//#region src/swap-vm/instructions/empty.ts
|
|
1115
|
+
var EmptyCoder = class {
|
|
1116
|
+
encode(_) {
|
|
1117
|
+
return __1inch_sdk_core.HexString.EMPTY;
|
|
1118
|
+
}
|
|
1119
|
+
decode(_) {
|
|
1120
|
+
return new EmptyArgs();
|
|
1121
|
+
}
|
|
1122
|
+
};
|
|
1123
|
+
var EmptyArgs = class {
|
|
1124
|
+
static CODER = new EmptyCoder();
|
|
1125
|
+
toJSON() {
|
|
1126
|
+
return null;
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
const EMPTY_OPCODE = new Opcode(Symbol("empty"), EmptyArgs.CODER);
|
|
1130
|
+
|
|
1131
|
+
//#endregion
|
|
1132
|
+
//#region src/swap-vm/programs/program-builder.ts
|
|
1133
|
+
/**
|
|
1134
|
+
* Abstract base class for building SwapVM programs
|
|
1135
|
+
**/
|
|
1136
|
+
var ProgramBuilder = class {
|
|
1137
|
+
program = [];
|
|
1138
|
+
constructor(ixsSet) {
|
|
1139
|
+
this.ixsSet = ixsSet;
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* Decodes a SwapVM program into builder instructions
|
|
1143
|
+
**/
|
|
1144
|
+
decode(program) {
|
|
1145
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(program.toString());
|
|
1146
|
+
while (!iter.isEmpty()) {
|
|
1147
|
+
const opcodeIdx = Number(iter.nextByte());
|
|
1148
|
+
const argsLength = Number(iter.nextByte());
|
|
1149
|
+
const argsHex = argsLength ? iter.nextBytes(argsLength) : "0x";
|
|
1150
|
+
if (opcodeIdx === 0) throw new Error("Invalid opcode: 0 (NOT_INSTRUCTION)");
|
|
1151
|
+
const opcode = this.ixsSet[opcodeIdx];
|
|
1152
|
+
if (!opcode) throw new Error(`Opcode at index ${opcodeIdx} is missing`);
|
|
1153
|
+
this.program.push(opcode.createIx(opcode.argsCoder().decode(new __1inch_sdk_core.HexString(argsHex))));
|
|
1154
|
+
}
|
|
1155
|
+
return this;
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Builds the SwapVM program bytecode from accumulated instructions
|
|
1159
|
+
**/
|
|
1160
|
+
build() {
|
|
1161
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1162
|
+
for (const ix of this.program) {
|
|
1163
|
+
const { args, opcode } = ix;
|
|
1164
|
+
const opcodeIdx = this.ixsSet.findIndex((o) => o.id === opcode.id);
|
|
1165
|
+
const coder = opcode.argsCoder();
|
|
1166
|
+
const encoded = coder.encode(args);
|
|
1167
|
+
const encodedBytes = (0, __1inch_byte_utils.trim0x)(encoded.toString());
|
|
1168
|
+
builder.addByte(BigInt(opcodeIdx)).addByte(BigInt(encodedBytes.length / 2));
|
|
1169
|
+
if (encodedBytes.length) builder.addBytes((0, __1inch_byte_utils.add0x)(encodedBytes));
|
|
1170
|
+
}
|
|
1171
|
+
return new SwapVmProgram(builder.asHex());
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Returns the current list of instructions in the program
|
|
1175
|
+
**/
|
|
1176
|
+
getInstructions() {
|
|
1177
|
+
return this.program;
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Adds an instruction to the program with validation
|
|
1181
|
+
**/
|
|
1182
|
+
add(ix) {
|
|
1183
|
+
const opcodeId = this.ixsSet.findIndex((o) => o.id === ix.opcode.id);
|
|
1184
|
+
if (opcodeId === -1) {
|
|
1185
|
+
const opcodes = this.ixsSet.map((i) => String(i.id)).filter((s) => s !== EMPTY_OPCODE.toString()).join(", ");
|
|
1186
|
+
throw new Error(`Invalid opcode ${String(ix.opcode.id)}: Supported opcodes: ${opcodes}`);
|
|
1187
|
+
}
|
|
1188
|
+
this.program.push(ix);
|
|
1189
|
+
return this;
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
|
|
1193
|
+
//#endregion
|
|
1194
|
+
//#region src/swap-vm/instructions/balances/balances-args-coder.ts
|
|
1195
|
+
var BalancesArgsCoder = class {
|
|
1196
|
+
encode(args) {
|
|
1197
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1198
|
+
builder.addUint16(BigInt(args.tokenBalances.length));
|
|
1199
|
+
for (const { tokenHalf } of args.tokenBalances) builder.addBytes(tokenHalf.toString());
|
|
1200
|
+
for (const { value } of args.tokenBalances) builder.addUint256(value);
|
|
1201
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
1202
|
+
}
|
|
1203
|
+
decode(data) {
|
|
1204
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
1205
|
+
const tokenCount = Number(iter.nextUint16());
|
|
1206
|
+
const tokenHalfs = [];
|
|
1207
|
+
for (let i = 0; i < tokenCount; i++) {
|
|
1208
|
+
const bytes = iter.nextBytes(10);
|
|
1209
|
+
const hexString = (0, __1inch_byte_utils.add0x)(bytes);
|
|
1210
|
+
tokenHalfs.push(__1inch_sdk_core.AddressHalf.fromHex(hexString));
|
|
1211
|
+
}
|
|
1212
|
+
const tokenBalances = [];
|
|
1213
|
+
for (let i = 0; i < tokenCount; i++) tokenBalances.push({
|
|
1214
|
+
tokenHalf: tokenHalfs[i],
|
|
1215
|
+
value: BigInt(iter.nextUint256())
|
|
1216
|
+
});
|
|
1217
|
+
return new BalancesArgs(tokenBalances);
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
//#endregion
|
|
1222
|
+
//#region src/swap-vm/instructions/balances/balances-args.ts
|
|
1223
|
+
/**
|
|
1224
|
+
* Arguments for setBalances and balances instructions containing token-amount pairs
|
|
1225
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Balances.sol#L10
|
|
1226
|
+
**/
|
|
1227
|
+
var BalancesArgs = class BalancesArgs {
|
|
1228
|
+
static CODER = new BalancesArgsCoder();
|
|
1229
|
+
constructor(tokenBalances) {
|
|
1230
|
+
this.tokenBalances = tokenBalances;
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* Decodes hex data into BalancesArgs instance
|
|
1234
|
+
**/
|
|
1235
|
+
static decode(data) {
|
|
1236
|
+
return BalancesArgs.CODER.decode(data);
|
|
1237
|
+
}
|
|
1238
|
+
toJSON() {
|
|
1239
|
+
return { tokenBalances: this.tokenBalances.map(({ tokenHalf, value }) => ({
|
|
1240
|
+
token: tokenHalf.toString(),
|
|
1241
|
+
value: value.toString()
|
|
1242
|
+
})) };
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
//#endregion
|
|
1247
|
+
//#region src/swap-vm/instructions/balances/opcodes.ts
|
|
1248
|
+
/**
|
|
1249
|
+
* Sets initial token balances for the swap program
|
|
1250
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Balances.sol#L59
|
|
1251
|
+
**/
|
|
1252
|
+
const staticBalancesXD = new Opcode(Symbol("Balances.staticBalancesXD"), BalancesArgs.CODER);
|
|
1253
|
+
/**
|
|
1254
|
+
* Reads token balances from program data or contract storage
|
|
1255
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Balances.sol#L89
|
|
1256
|
+
**/
|
|
1257
|
+
const dynamicBalancesXD = new Opcode(Symbol("Balances.dynamicBalancesXD"), BalancesArgs.CODER);
|
|
1258
|
+
|
|
1259
|
+
//#endregion
|
|
1260
|
+
//#region src/swap-vm/instructions/balances/index.ts
|
|
1261
|
+
var balances_exports = {};
|
|
1262
|
+
__export(balances_exports, {
|
|
1263
|
+
BalancesArgs: () => BalancesArgs,
|
|
1264
|
+
dynamicBalancesXD: () => dynamicBalancesXD,
|
|
1265
|
+
staticBalancesXD: () => staticBalancesXD
|
|
1266
|
+
});
|
|
1267
|
+
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/swap-vm/instructions/controls/jump-args-coder.ts
|
|
1270
|
+
var JumpArgsCoder = class {
|
|
1271
|
+
encode(args) {
|
|
1272
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1273
|
+
builder.addUint16(args.nextPC);
|
|
1274
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
1275
|
+
}
|
|
1276
|
+
decode(data) {
|
|
1277
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
1278
|
+
const nextPC = iter.nextUint16();
|
|
1279
|
+
return new JumpArgs(nextPC);
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
//#endregion
|
|
1284
|
+
//#region src/swap-vm/instructions/controls/jump-args.ts
|
|
1285
|
+
const UINT_16_MAX$3 = 0xffffn;
|
|
1286
|
+
/**
|
|
1287
|
+
* Arguments for jump instructions containing target program counter
|
|
1288
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
|
|
1289
|
+
**/
|
|
1290
|
+
var JumpArgs = class JumpArgs {
|
|
1291
|
+
static CODER = new JumpArgsCoder();
|
|
1292
|
+
constructor(nextPC) {
|
|
1293
|
+
this.nextPC = nextPC;
|
|
1294
|
+
(0, node_assert.default)(nextPC <= UINT_16_MAX$3 && nextPC >= 0n, `Invalid nextPC value: ${nextPC}. Must be between 0 and 65535`);
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Decodes hex data into JumpArgs instance
|
|
1298
|
+
**/
|
|
1299
|
+
static decode(data) {
|
|
1300
|
+
return JumpArgs.CODER.decode(data);
|
|
1301
|
+
}
|
|
1302
|
+
toJSON() {
|
|
1303
|
+
return { nextPC: this.nextPC };
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1307
|
+
//#endregion
|
|
1308
|
+
//#region src/swap-vm/instructions/controls/jump-if-token-args-coder.ts
|
|
1309
|
+
var JumpIfTokenArgsCoder = class {
|
|
1310
|
+
encode(args) {
|
|
1311
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1312
|
+
builder.addBytes(args.tokenTail.toString());
|
|
1313
|
+
builder.addUint16(args.nextPC);
|
|
1314
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
1315
|
+
}
|
|
1316
|
+
decode(data) {
|
|
1317
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
1318
|
+
const tokenTailBytes = iter.nextBytes(10);
|
|
1319
|
+
const tokenTail = __1inch_sdk_core.AddressHalf.fromHex(tokenTailBytes);
|
|
1320
|
+
const nextPC = BigInt(iter.nextUint16());
|
|
1321
|
+
return new JumpIfTokenArgs(tokenTail, nextPC);
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
|
|
1325
|
+
//#endregion
|
|
1326
|
+
//#region src/swap-vm/instructions/controls/jump-if-token-args.ts
|
|
1327
|
+
var JumpIfTokenArgs = class JumpIfTokenArgs {
|
|
1328
|
+
static CODER = new JumpIfTokenArgsCoder();
|
|
1329
|
+
constructor(tokenTail, nextPC) {
|
|
1330
|
+
this.tokenTail = tokenTail;
|
|
1331
|
+
this.nextPC = nextPC;
|
|
1332
|
+
}
|
|
1333
|
+
static decode(data) {
|
|
1334
|
+
return JumpIfTokenArgs.CODER.decode(data);
|
|
1335
|
+
}
|
|
1336
|
+
toJSON() {
|
|
1337
|
+
return {
|
|
1338
|
+
tokenTail: this.tokenTail.toString(),
|
|
1339
|
+
nextPC: this.nextPC
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
|
|
1344
|
+
//#endregion
|
|
1345
|
+
//#region src/swap-vm/instructions/controls/deadline-args-coder.ts
|
|
1346
|
+
var DeadlineArgsCoder = class {
|
|
1347
|
+
encode(args) {
|
|
1348
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1349
|
+
builder.addUint40(args.deadline);
|
|
1350
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
1351
|
+
}
|
|
1352
|
+
decode(data) {
|
|
1353
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
1354
|
+
const deadline$1 = iter.nextUint40();
|
|
1355
|
+
return new DeadlineArgs(deadline$1);
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
|
|
1359
|
+
//#endregion
|
|
1360
|
+
//#region src/swap-vm/instructions/controls/deadline-args.ts
|
|
1361
|
+
var DeadlineArgs = class DeadlineArgs {
|
|
1362
|
+
static CODER = new DeadlineArgsCoder();
|
|
1363
|
+
constructor(deadline$1) {
|
|
1364
|
+
this.deadline = deadline$1;
|
|
1365
|
+
}
|
|
1366
|
+
static decode(data) {
|
|
1367
|
+
return DeadlineArgs.CODER.decode(data);
|
|
1368
|
+
}
|
|
1369
|
+
toJSON() {
|
|
1370
|
+
return { deadline: this.deadline.toString() };
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
|
|
1374
|
+
//#endregion
|
|
1375
|
+
//#region src/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args-coder.ts
|
|
1376
|
+
var OnlyTakerTokenBalanceNonZeroArgsCoder = class {
|
|
1377
|
+
encode(args) {
|
|
1378
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1379
|
+
builder.addAddress(args.token.toString());
|
|
1380
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
1381
|
+
}
|
|
1382
|
+
decode(data) {
|
|
1383
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
1384
|
+
const token = new __1inch_sdk_core.Address(iter.nextUint160());
|
|
1385
|
+
return new OnlyTakerTokenBalanceNonZeroArgs(token);
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1389
|
+
//#endregion
|
|
1390
|
+
//#region src/swap-vm/instructions/controls/only-taker-token-balance-non-zero-args.ts
|
|
1391
|
+
/**
|
|
1392
|
+
* Arguments for checking if taker holds any amount of a token
|
|
1393
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
|
|
1394
|
+
**/
|
|
1395
|
+
var OnlyTakerTokenBalanceNonZeroArgs = class OnlyTakerTokenBalanceNonZeroArgs {
|
|
1396
|
+
static CODER = new OnlyTakerTokenBalanceNonZeroArgsCoder();
|
|
1397
|
+
constructor(token) {
|
|
1398
|
+
this.token = token;
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Decodes hex data into OnlyTakerTokenBalanceNonZeroArgs instance
|
|
1402
|
+
**/
|
|
1403
|
+
static decode(data) {
|
|
1404
|
+
return OnlyTakerTokenBalanceNonZeroArgs.CODER.decode(data);
|
|
1405
|
+
}
|
|
1406
|
+
toJSON() {
|
|
1407
|
+
return { token: this.token.toString() };
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
|
|
1411
|
+
//#endregion
|
|
1412
|
+
//#region src/swap-vm/instructions/controls/only-taker-token-balance-gte-args-coder.ts
|
|
1413
|
+
var OnlyTakerTokenBalanceGteArgsCoder = class {
|
|
1414
|
+
encode(args) {
|
|
1415
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1416
|
+
builder.addAddress(args.token.toString());
|
|
1417
|
+
builder.addUint256(args.minAmount);
|
|
1418
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
1419
|
+
}
|
|
1420
|
+
decode(data) {
|
|
1421
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
1422
|
+
const token = new __1inch_sdk_core.Address(iter.nextUint160());
|
|
1423
|
+
const minAmount = BigInt(iter.nextUint256());
|
|
1424
|
+
return new OnlyTakerTokenBalanceGteArgs(token, minAmount);
|
|
1425
|
+
}
|
|
1426
|
+
};
|
|
1427
|
+
|
|
1428
|
+
//#endregion
|
|
1429
|
+
//#region src/swap-vm/instructions/controls/only-taker-token-balance-gte-args.ts
|
|
1430
|
+
/**
|
|
1431
|
+
* Arguments for checking if taker holds at least specified amount of token
|
|
1432
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
|
|
1433
|
+
**/
|
|
1434
|
+
var OnlyTakerTokenBalanceGteArgs = class OnlyTakerTokenBalanceGteArgs {
|
|
1435
|
+
static CODER = new OnlyTakerTokenBalanceGteArgsCoder();
|
|
1436
|
+
constructor(token, minAmount) {
|
|
1437
|
+
this.token = token;
|
|
1438
|
+
this.minAmount = minAmount;
|
|
1439
|
+
(0, node_assert.default)(minAmount >= 0n, "minAmount must be non-negative");
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Decodes hex data into OnlyTakerTokenBalanceGteArgs instance
|
|
1443
|
+
**/
|
|
1444
|
+
static decode(data) {
|
|
1445
|
+
return OnlyTakerTokenBalanceGteArgs.CODER.decode(data);
|
|
1446
|
+
}
|
|
1447
|
+
toJSON() {
|
|
1448
|
+
return {
|
|
1449
|
+
token: this.token.toString(),
|
|
1450
|
+
minAmount: this.minAmount.toString()
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
|
|
1455
|
+
//#endregion
|
|
1456
|
+
//#region src/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args-coder.ts
|
|
1457
|
+
var OnlyTakerTokenSupplyShareGteArgsCoder = class {
|
|
1458
|
+
encode(args) {
|
|
1459
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1460
|
+
builder.addAddress(args.token.toString());
|
|
1461
|
+
builder.addUint64(args.minShareE18);
|
|
1462
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
1463
|
+
}
|
|
1464
|
+
decode(data) {
|
|
1465
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
1466
|
+
const token = new __1inch_sdk_core.Address(iter.nextUint160());
|
|
1467
|
+
const bytes = iter.nextBytes(8);
|
|
1468
|
+
const minShareE18 = BigInt((0, __1inch_byte_utils.add0x)(bytes));
|
|
1469
|
+
return new OnlyTakerTokenSupplyShareGteArgs(token, minShareE18);
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
|
|
1473
|
+
//#endregion
|
|
1474
|
+
//#region src/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.ts
|
|
1475
|
+
const UINT_64_MAX$4 = 0xffffffffffffffffn;
|
|
1476
|
+
/**
|
|
1477
|
+
* Arguments for checking if taker holds at least specified share of token's total supply
|
|
1478
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
|
|
1479
|
+
**/
|
|
1480
|
+
var OnlyTakerTokenSupplyShareGteArgs = class OnlyTakerTokenSupplyShareGteArgs {
|
|
1481
|
+
static CODER = new OnlyTakerTokenSupplyShareGteArgsCoder();
|
|
1482
|
+
constructor(token, minShareE18) {
|
|
1483
|
+
this.token = token;
|
|
1484
|
+
this.minShareE18 = minShareE18;
|
|
1485
|
+
(0, node_assert.default)(minShareE18 >= 0n && minShareE18 <= UINT_64_MAX$4, `Invalid minShareE18 value: ${minShareE18}. Must be a valid uint64`);
|
|
1486
|
+
}
|
|
1487
|
+
/**
|
|
1488
|
+
* Decodes hex data into OnlyTakerTokenSupplyShareGteArgs instance
|
|
1489
|
+
**/
|
|
1490
|
+
static decode(data) {
|
|
1491
|
+
return OnlyTakerTokenSupplyShareGteArgs.CODER.decode(data);
|
|
1492
|
+
}
|
|
1493
|
+
toJSON() {
|
|
1494
|
+
return {
|
|
1495
|
+
token: this.token.toString(),
|
|
1496
|
+
minShareE18: this.minShareE18.toString()
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
//#endregion
|
|
1502
|
+
//#region src/swap-vm/instructions/controls/salt-args-coder.ts
|
|
1503
|
+
var SaltArgsCoder = class {
|
|
1504
|
+
encode(args) {
|
|
1505
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1506
|
+
builder.addUint64(args.salt);
|
|
1507
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
1508
|
+
}
|
|
1509
|
+
decode(data) {
|
|
1510
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
1511
|
+
const bytes = iter.nextUint64();
|
|
1512
|
+
return new SaltArgs(bytes);
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
|
|
1516
|
+
//#endregion
|
|
1517
|
+
//#region src/swap-vm/instructions/controls/salt-args.ts
|
|
1518
|
+
/**
|
|
1519
|
+
* Arguments for salt instruction used to add uniqueness to order hashes
|
|
1520
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L48
|
|
1521
|
+
**/
|
|
1522
|
+
var SaltArgs = class SaltArgs {
|
|
1523
|
+
static CODER = new SaltArgsCoder();
|
|
1524
|
+
constructor(salt$1) {
|
|
1525
|
+
this.salt = salt$1;
|
|
1526
|
+
(0, node_assert.default)(salt$1 >= 0n && salt$1 <= __1inch_byte_utils.UINT_64_MAX, `Invalid salt value: ${salt$1}. Must be a valid uint64`);
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1529
|
+
* Decodes hex data into SaltArgs instance
|
|
1530
|
+
**/
|
|
1531
|
+
static decode(data) {
|
|
1532
|
+
return SaltArgs.CODER.decode(data);
|
|
1533
|
+
}
|
|
1534
|
+
toJSON() {
|
|
1535
|
+
return { salt: this.salt.toString() };
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
|
|
1539
|
+
//#endregion
|
|
1540
|
+
//#region src/swap-vm/instructions/controls/opcodes.ts
|
|
1541
|
+
/**
|
|
1542
|
+
* Unconditional jump to specified program counter
|
|
1543
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L52
|
|
1544
|
+
**/
|
|
1545
|
+
const jump = new Opcode(Symbol("Controls.jump"), JumpArgs.CODER);
|
|
1546
|
+
const jumpIfTokenIn = new Opcode(Symbol("Controls.jumpIfTokenIn"), JumpIfTokenArgs.CODER);
|
|
1547
|
+
const jumpIfTokenOut = new Opcode(Symbol("Controls.jumpIfTokenOut"), JumpIfTokenArgs.CODER);
|
|
1548
|
+
const deadline = new Opcode(Symbol("Controls.deadline"), DeadlineArgs.CODER);
|
|
1549
|
+
/**
|
|
1550
|
+
* Requires taker to hold any amount of specified token (supports NFTs)
|
|
1551
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L77
|
|
1552
|
+
**/
|
|
1553
|
+
const onlyTakerTokenBalanceNonZero = new Opcode(Symbol("Controls.onlyTakerTokenBalanceNonZero"), OnlyTakerTokenBalanceNonZeroArgs.CODER);
|
|
1554
|
+
/**
|
|
1555
|
+
* Requires taker to hold at least specified amount of token
|
|
1556
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L86
|
|
1557
|
+
*/
|
|
1558
|
+
const onlyTakerTokenBalanceGte = new Opcode(Symbol("Controls.onlyTakerTokenBalanceGte"), OnlyTakerTokenBalanceGteArgs.CODER);
|
|
1559
|
+
/**
|
|
1560
|
+
* Requires taker to hold at least specified share of token's total supply
|
|
1561
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L96
|
|
1562
|
+
**/
|
|
1563
|
+
const onlyTakerTokenSupplyShareGte = new Opcode(Symbol("Controls.onlyTakerTokenSupplyShareGte"), OnlyTakerTokenSupplyShareGteArgs.CODER);
|
|
1564
|
+
/**
|
|
1565
|
+
* No-op instruction used to add uniqueness to order hashes (prevents replay attacks)
|
|
1566
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L48
|
|
1567
|
+
**/
|
|
1568
|
+
const salt = new Opcode(Symbol("Controls.salt"), SaltArgs.CODER);
|
|
1569
|
+
|
|
1570
|
+
//#endregion
|
|
1571
|
+
//#region src/swap-vm/instructions/controls/index.ts
|
|
1572
|
+
var controls_exports = {};
|
|
1573
|
+
__export(controls_exports, {
|
|
1574
|
+
DeadlineArgs: () => DeadlineArgs,
|
|
1575
|
+
JumpArgs: () => JumpArgs,
|
|
1576
|
+
JumpIfTokenArgs: () => JumpIfTokenArgs,
|
|
1577
|
+
OnlyTakerTokenBalanceGteArgs: () => OnlyTakerTokenBalanceGteArgs,
|
|
1578
|
+
OnlyTakerTokenBalanceNonZeroArgs: () => OnlyTakerTokenBalanceNonZeroArgs,
|
|
1579
|
+
OnlyTakerTokenSupplyShareGteArgs: () => OnlyTakerTokenSupplyShareGteArgs,
|
|
1580
|
+
SaltArgs: () => SaltArgs,
|
|
1581
|
+
deadline: () => deadline,
|
|
1582
|
+
jump: () => jump,
|
|
1583
|
+
jumpIfTokenIn: () => jumpIfTokenIn,
|
|
1584
|
+
jumpIfTokenOut: () => jumpIfTokenOut,
|
|
1585
|
+
onlyTakerTokenBalanceGte: () => onlyTakerTokenBalanceGte,
|
|
1586
|
+
onlyTakerTokenBalanceNonZero: () => onlyTakerTokenBalanceNonZero,
|
|
1587
|
+
onlyTakerTokenSupplyShareGte: () => onlyTakerTokenSupplyShareGte,
|
|
1588
|
+
salt: () => salt
|
|
1589
|
+
});
|
|
1590
|
+
|
|
1591
|
+
//#endregion
|
|
1592
|
+
//#region src/swap-vm/instructions/invalidators/invalidate-bit-1d-args-coder.ts
|
|
1593
|
+
var InvalidateBit1DArgsCoder = class {
|
|
1594
|
+
encode(args) {
|
|
1595
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1596
|
+
builder.addUint32(args.bitIndex);
|
|
1597
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
1598
|
+
}
|
|
1599
|
+
decode(data) {
|
|
1600
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
1601
|
+
const bitIndex = iter.nextUint32();
|
|
1602
|
+
return new InvalidateBit1DArgs(bitIndex);
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
|
|
1606
|
+
//#endregion
|
|
1607
|
+
//#region src/swap-vm/instructions/invalidators/invalidate-bit-1d-args.ts
|
|
1608
|
+
/**
|
|
1609
|
+
* Arguments for invalidateBit1D instruction to invalidate a specific bit index
|
|
1610
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Invalidators.sol#L75
|
|
1611
|
+
**/
|
|
1612
|
+
var InvalidateBit1DArgs = class InvalidateBit1DArgs {
|
|
1613
|
+
static CODER = new InvalidateBit1DArgsCoder();
|
|
1614
|
+
constructor(bitIndex) {
|
|
1615
|
+
this.bitIndex = bitIndex;
|
|
1616
|
+
(0, node_assert.default)(bitIndex >= 0n && bitIndex <= __1inch_byte_utils.UINT_32_MAX, `Invalid bitIndex value: ${bitIndex}. Must be a valid uint32`);
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Decodes hex data into InvalidateBit1DArgs instance
|
|
1620
|
+
**/
|
|
1621
|
+
static decode(data) {
|
|
1622
|
+
return InvalidateBit1DArgs.CODER.decode(data);
|
|
1623
|
+
}
|
|
1624
|
+
toJSON() {
|
|
1625
|
+
return { bitIndex: this.bitIndex.toString() };
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1628
|
+
|
|
1629
|
+
//#endregion
|
|
1630
|
+
//#region src/swap-vm/instructions/invalidators/invalidate-token-in-1d-args-coder.ts
|
|
1631
|
+
var InvalidateTokenIn1DArgsCoder = class {
|
|
1632
|
+
encode(_args) {
|
|
1633
|
+
return new __1inch_sdk_core.HexString("0x");
|
|
1634
|
+
}
|
|
1635
|
+
decode(_data) {
|
|
1636
|
+
return new InvalidateTokenIn1DArgs();
|
|
1637
|
+
}
|
|
1638
|
+
};
|
|
1639
|
+
|
|
1640
|
+
//#endregion
|
|
1641
|
+
//#region src/swap-vm/instructions/invalidators/invalidate-token-in-1d-args.ts
|
|
1642
|
+
var InvalidateTokenIn1DArgs = class InvalidateTokenIn1DArgs {
|
|
1643
|
+
static CODER = new InvalidateTokenIn1DArgsCoder();
|
|
1644
|
+
constructor() {}
|
|
1645
|
+
static decode(data) {
|
|
1646
|
+
return InvalidateTokenIn1DArgs.CODER.decode(data);
|
|
1647
|
+
}
|
|
1648
|
+
toJSON() {
|
|
1649
|
+
return {};
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
|
|
1653
|
+
//#endregion
|
|
1654
|
+
//#region src/swap-vm/instructions/invalidators/invalidate-token-out-1d-args-coder.ts
|
|
1655
|
+
var InvalidateTokenOut1DArgsCoder = class {
|
|
1656
|
+
encode(_args) {
|
|
1657
|
+
return new __1inch_sdk_core.HexString("0x");
|
|
1658
|
+
}
|
|
1659
|
+
decode(_data) {
|
|
1660
|
+
return new InvalidateTokenOut1DArgs();
|
|
1661
|
+
}
|
|
1662
|
+
};
|
|
1663
|
+
|
|
1664
|
+
//#endregion
|
|
1665
|
+
//#region src/swap-vm/instructions/invalidators/invalidate-token-out-1d-args.ts
|
|
1666
|
+
var InvalidateTokenOut1DArgs = class InvalidateTokenOut1DArgs {
|
|
1667
|
+
static CODER = new InvalidateTokenOut1DArgsCoder();
|
|
1668
|
+
constructor() {}
|
|
1669
|
+
static decode(data) {
|
|
1670
|
+
return InvalidateTokenOut1DArgs.CODER.decode(data);
|
|
1671
|
+
}
|
|
1672
|
+
toJSON() {
|
|
1673
|
+
return {};
|
|
1674
|
+
}
|
|
1675
|
+
};
|
|
1676
|
+
|
|
1677
|
+
//#endregion
|
|
1678
|
+
//#region src/swap-vm/instructions/invalidators/opcodes.ts
|
|
1679
|
+
/**
|
|
1680
|
+
* Invalidates a specific bit index for order uniqueness
|
|
1681
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Invalidators.sol#L75
|
|
1682
|
+
**/
|
|
1683
|
+
const invalidateBit1D = new Opcode(Symbol("Invalidators.invalidateBit1D"), InvalidateBit1DArgs.CODER);
|
|
1684
|
+
/**
|
|
1685
|
+
* Invalidates order by token input to prevent re-use
|
|
1686
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Invalidators.sol#L85
|
|
1687
|
+
**/
|
|
1688
|
+
const invalidateTokenIn1D = new Opcode(Symbol("Invalidators.invalidateTokenIn1D"), InvalidateTokenIn1DArgs.CODER);
|
|
1689
|
+
/**
|
|
1690
|
+
* Invalidates order by token output to prevent re-use
|
|
1691
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Invalidators.sol#L103
|
|
1692
|
+
**/
|
|
1693
|
+
const invalidateTokenOut1D = new Opcode(Symbol("Invalidators.invalidateTokenOut1D"), InvalidateTokenOut1DArgs.CODER);
|
|
1694
|
+
|
|
1695
|
+
//#endregion
|
|
1696
|
+
//#region src/swap-vm/instructions/invalidators/index.ts
|
|
1697
|
+
var invalidators_exports = {};
|
|
1698
|
+
__export(invalidators_exports, {
|
|
1699
|
+
InvalidateBit1DArgs: () => InvalidateBit1DArgs,
|
|
1700
|
+
InvalidateTokenIn1DArgs: () => InvalidateTokenIn1DArgs,
|
|
1701
|
+
InvalidateTokenOut1DArgs: () => InvalidateTokenOut1DArgs,
|
|
1702
|
+
invalidateBit1D: () => invalidateBit1D,
|
|
1703
|
+
invalidateTokenIn1D: () => invalidateTokenIn1D,
|
|
1704
|
+
invalidateTokenOut1D: () => invalidateTokenOut1D
|
|
1705
|
+
});
|
|
1706
|
+
|
|
1707
|
+
//#endregion
|
|
1708
|
+
//#region src/swap-vm/instructions/xyc-swap/xyc-swap-xd-args-coder.ts
|
|
1709
|
+
var XycSwapXDArgsCoder = class {
|
|
1710
|
+
encode(_args) {
|
|
1711
|
+
return new __1inch_sdk_core.HexString("0x");
|
|
1712
|
+
}
|
|
1713
|
+
decode(_data) {
|
|
1714
|
+
return new XycSwapXDArgs();
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
//#endregion
|
|
1719
|
+
//#region src/swap-vm/instructions/xyc-swap/xyc-swap-xd-args.ts
|
|
1720
|
+
/**
|
|
1721
|
+
* Arguments for xycSwapXD instruction (no arguments required)
|
|
1722
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCSwap.sol#L15
|
|
1723
|
+
**/
|
|
1724
|
+
var XycSwapXDArgs = class XycSwapXDArgs {
|
|
1725
|
+
static CODER = new XycSwapXDArgsCoder();
|
|
1726
|
+
constructor() {}
|
|
1727
|
+
/**
|
|
1728
|
+
* Decodes hex data into XycSwapXDArgs instance
|
|
1729
|
+
**/
|
|
1730
|
+
static decode(data) {
|
|
1731
|
+
return XycSwapXDArgs.CODER.decode(data);
|
|
1732
|
+
}
|
|
1733
|
+
toJSON() {
|
|
1734
|
+
return {};
|
|
1735
|
+
}
|
|
1736
|
+
};
|
|
1737
|
+
|
|
1738
|
+
//#endregion
|
|
1739
|
+
//#region src/swap-vm/instructions/xyc-swap/opcodes.ts
|
|
1740
|
+
/**
|
|
1741
|
+
* Basic swap using constant product formula (x*y=k)
|
|
1742
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCSwap.sol#L15
|
|
1743
|
+
**/
|
|
1744
|
+
const xycSwapXD = new Opcode(Symbol("XYCSwap.xycSwapXD"), XycSwapXDArgs.CODER);
|
|
1745
|
+
|
|
1746
|
+
//#endregion
|
|
1747
|
+
//#region src/swap-vm/instructions/xyc-swap/index.ts
|
|
1748
|
+
var xyc_swap_exports = {};
|
|
1749
|
+
__export(xyc_swap_exports, {
|
|
1750
|
+
XycSwapXDArgs: () => XycSwapXDArgs,
|
|
1751
|
+
xycSwapXD: () => xycSwapXD
|
|
1752
|
+
});
|
|
1753
|
+
|
|
1754
|
+
//#endregion
|
|
1755
|
+
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.ts
|
|
1756
|
+
var ConcentrateGrowLiquidityXDArgsCoder = class {
|
|
1757
|
+
encode(args) {
|
|
1758
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1759
|
+
builder.addUint16(BigInt(args.tokenDeltas.length));
|
|
1760
|
+
for (const { tokenHalf } of args.tokenDeltas) builder.addBytes(tokenHalf.toString());
|
|
1761
|
+
for (const { delta } of args.tokenDeltas) builder.addUint256(delta);
|
|
1762
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
1763
|
+
}
|
|
1764
|
+
decode(data) {
|
|
1765
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
1766
|
+
const tokenCount = Number(iter.nextUint16());
|
|
1767
|
+
const tokenHalves = [];
|
|
1768
|
+
for (let i = 0; i < tokenCount; i++) {
|
|
1769
|
+
const bytes = iter.nextBytes(10);
|
|
1770
|
+
tokenHalves.push(__1inch_sdk_core.AddressHalf.fromHex(bytes));
|
|
1771
|
+
}
|
|
1772
|
+
const tokenDeltas = [];
|
|
1773
|
+
for (let i = 0; i < tokenCount; i++) tokenDeltas.push({
|
|
1774
|
+
tokenHalf: tokenHalves[i],
|
|
1775
|
+
delta: BigInt(iter.nextUint256())
|
|
1776
|
+
});
|
|
1777
|
+
return new ConcentrateGrowLiquidityXDArgs(tokenDeltas);
|
|
1778
|
+
}
|
|
1779
|
+
};
|
|
1780
|
+
|
|
1781
|
+
//#endregion
|
|
1782
|
+
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.ts
|
|
1783
|
+
/**
|
|
1784
|
+
* Arguments for concentrateGrowLiquidityXD instruction with multiple token deltas
|
|
1785
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L139
|
|
1786
|
+
**/
|
|
1787
|
+
var ConcentrateGrowLiquidityXDArgs = class ConcentrateGrowLiquidityXDArgs {
|
|
1788
|
+
static CODER = new ConcentrateGrowLiquidityXDArgsCoder();
|
|
1789
|
+
constructor(tokenDeltas) {
|
|
1790
|
+
this.tokenDeltas = tokenDeltas;
|
|
1791
|
+
tokenDeltas.forEach((td, index) => {
|
|
1792
|
+
(0, node_assert.default)(td.delta >= 0n && td.delta <= __1inch_byte_utils.UINT_256_MAX, `Invalid delta at index ${index}: ${td.delta}. Must be >= 0 and <= UINT_256_MAX`);
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Decodes hex data into ConcentrateGrowLiquidityXDArgs instance
|
|
1797
|
+
**/
|
|
1798
|
+
static decode(data) {
|
|
1799
|
+
return ConcentrateGrowLiquidityXDArgs.CODER.decode(data);
|
|
1800
|
+
}
|
|
1801
|
+
toJSON() {
|
|
1802
|
+
return { tokenDeltas: this.tokenDeltas.map(({ tokenHalf, delta }) => ({
|
|
1803
|
+
token: tokenHalf.toString(),
|
|
1804
|
+
delta: delta.toString()
|
|
1805
|
+
})) };
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1808
|
+
|
|
1809
|
+
//#endregion
|
|
1810
|
+
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.ts
|
|
1811
|
+
var ConcentrateGrowLiquidity2DArgsCoder = class {
|
|
1812
|
+
encode(args) {
|
|
1813
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1814
|
+
builder.addUint256(args.deltaLt);
|
|
1815
|
+
builder.addUint256(args.deltaGt);
|
|
1816
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
1817
|
+
}
|
|
1818
|
+
decode(data) {
|
|
1819
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
1820
|
+
const deltaLt = iter.nextUint256();
|
|
1821
|
+
const deltaGt = iter.nextUint256();
|
|
1822
|
+
return new ConcentrateGrowLiquidity2DArgs(deltaLt, deltaGt);
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
|
|
1826
|
+
//#endregion
|
|
1827
|
+
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.ts
|
|
1828
|
+
/**
|
|
1829
|
+
* Arguments for concentrateGrowLiquidity2D instruction with two deltas
|
|
1830
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
|
|
1831
|
+
**/
|
|
1832
|
+
var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
|
|
1833
|
+
static CODER = new ConcentrateGrowLiquidity2DArgsCoder();
|
|
1834
|
+
constructor(deltaLt, deltaGt) {
|
|
1835
|
+
this.deltaLt = deltaLt;
|
|
1836
|
+
this.deltaGt = deltaGt;
|
|
1837
|
+
(0, node_assert.default)(deltaLt >= 0n && deltaLt <= __1inch_byte_utils.UINT_256_MAX, `Invalid deltaLt: ${deltaLt}. Must be >= 0 and <= UINT_256_MAX`);
|
|
1838
|
+
(0, node_assert.default)(deltaGt >= 0n && deltaGt <= __1inch_byte_utils.UINT_256_MAX, `Invalid deltaGt: ${deltaGt}. Must be >= 0 and <= UINT_256_MAX`);
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Helper to create args from token addresses and deltas (handles ordering)
|
|
1842
|
+
**/
|
|
1843
|
+
static fromTokenDeltas(tokenA, tokenB, deltaA, deltaB) {
|
|
1844
|
+
const tokenABigInt = BigInt(tokenA.toString());
|
|
1845
|
+
const tokenBBigInt = BigInt(tokenB.toString());
|
|
1846
|
+
const [deltaLt, deltaGt] = tokenABigInt < tokenBBigInt ? [deltaA, deltaB] : [deltaB, deltaA];
|
|
1847
|
+
return new ConcentrateGrowLiquidity2DArgs(deltaLt, deltaGt);
|
|
1848
|
+
}
|
|
1849
|
+
/**
|
|
1850
|
+
* Decodes hex data into ConcentrateGrowLiquidity2DArgs instance
|
|
1851
|
+
**/
|
|
1852
|
+
static decode(data) {
|
|
1853
|
+
return ConcentrateGrowLiquidity2DArgs.CODER.decode(data);
|
|
1854
|
+
}
|
|
1855
|
+
toJSON() {
|
|
1856
|
+
return {
|
|
1857
|
+
deltaLt: this.deltaLt.toString(),
|
|
1858
|
+
deltaGt: this.deltaGt.toString()
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
};
|
|
1862
|
+
|
|
1863
|
+
//#endregion
|
|
1864
|
+
//#region src/swap-vm/instructions/concentrate/opcodes.ts
|
|
1865
|
+
/**
|
|
1866
|
+
* Concentrates liquidity within price bounds for multiple tokens
|
|
1867
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L139
|
|
1868
|
+
**/
|
|
1869
|
+
const concentrateGrowLiquidityXD = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidityXD"), ConcentrateGrowLiquidityXDArgs.CODER);
|
|
1870
|
+
/**
|
|
1871
|
+
* Concentrates liquidity within price bounds for two tokens
|
|
1872
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
|
|
1873
|
+
**/
|
|
1874
|
+
const concentrateGrowLiquidity2D = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidity2D"), ConcentrateGrowLiquidity2DArgs.CODER);
|
|
1875
|
+
|
|
1876
|
+
//#endregion
|
|
1877
|
+
//#region src/swap-vm/instructions/concentrate/utils.ts
|
|
1878
|
+
const TEN_POW_18 = 10n ** 18n;
|
|
1879
|
+
function computeDeltas(balanceA, balanceB, price, priceMin, priceMax) {
|
|
1880
|
+
const sqrtMin = sqrt(price * TEN_POW_18 / priceMin);
|
|
1881
|
+
const sqrtMax = sqrt(priceMax * TEN_POW_18 / price);
|
|
1882
|
+
return {
|
|
1883
|
+
deltaA: price == priceMin ? 0n : balanceA * TEN_POW_18 / (sqrtMin - TEN_POW_18),
|
|
1884
|
+
deltaB: price == priceMax ? 0n : balanceB * TEN_POW_18 / (sqrtMax - TEN_POW_18)
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
function sqrt(value) {
|
|
1888
|
+
if (value < 0n) throw "square root of negative numbers is not supported";
|
|
1889
|
+
if (value < 2n) return value;
|
|
1890
|
+
function newtonIteration(n, x0) {
|
|
1891
|
+
const x1 = n / x0 + x0 >> 1n;
|
|
1892
|
+
if (x0 === x1 || x0 === x1 - 1n) return x0;
|
|
1893
|
+
return newtonIteration(n, x1);
|
|
1894
|
+
}
|
|
1895
|
+
return newtonIteration(value, 1n);
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
//#endregion
|
|
1899
|
+
//#region src/swap-vm/instructions/concentrate/index.ts
|
|
1900
|
+
var concentrate_exports = {};
|
|
1901
|
+
__export(concentrate_exports, {
|
|
1902
|
+
ConcentrateGrowLiquidity2DArgs: () => ConcentrateGrowLiquidity2DArgs,
|
|
1903
|
+
ConcentrateGrowLiquidityXDArgs: () => ConcentrateGrowLiquidityXDArgs,
|
|
1904
|
+
computeDeltas: () => computeDeltas,
|
|
1905
|
+
concentrateGrowLiquidity2D: () => concentrateGrowLiquidity2D,
|
|
1906
|
+
concentrateGrowLiquidityXD: () => concentrateGrowLiquidityXD
|
|
1907
|
+
});
|
|
1908
|
+
|
|
1909
|
+
//#endregion
|
|
1910
|
+
//#region src/swap-vm/instructions/decay/decay-xd-args-coder.ts
|
|
1911
|
+
var DecayXDArgsCoder = class {
|
|
1912
|
+
encode(args) {
|
|
1913
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1914
|
+
builder.addUint16(args.decayPeriod);
|
|
1915
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
1916
|
+
}
|
|
1917
|
+
decode(data) {
|
|
1918
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
1919
|
+
const decayPeriod = iter.nextUint16();
|
|
1920
|
+
return new DecayXDArgs(decayPeriod);
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
|
|
1924
|
+
//#endregion
|
|
1925
|
+
//#region src/swap-vm/instructions/decay/decay-xd-args.ts
|
|
1926
|
+
/**
|
|
1927
|
+
* Arguments for decayXD instruction with decay period
|
|
1928
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Decay.sol#L79
|
|
1929
|
+
**/
|
|
1930
|
+
var DecayXDArgs = class DecayXDArgs {
|
|
1931
|
+
static CODER = new DecayXDArgsCoder();
|
|
1932
|
+
constructor(decayPeriod) {
|
|
1933
|
+
this.decayPeriod = decayPeriod;
|
|
1934
|
+
(0, node_assert.default)(decayPeriod >= 0n && decayPeriod <= __1inch_byte_utils.UINT_16_MAX, `Invalid decayPeriod value: ${decayPeriod}. Must be a valid uint16`);
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Decodes hex data into DecayXDArgs instance
|
|
1938
|
+
**/
|
|
1939
|
+
static decode(data) {
|
|
1940
|
+
return DecayXDArgs.CODER.decode(data);
|
|
1941
|
+
}
|
|
1942
|
+
toJSON() {
|
|
1943
|
+
return { decayPeriod: this.decayPeriod.toString() };
|
|
1944
|
+
}
|
|
1945
|
+
};
|
|
1946
|
+
|
|
1947
|
+
//#endregion
|
|
1948
|
+
//#region src/swap-vm/instructions/decay/opcodes.ts
|
|
1949
|
+
/**
|
|
1950
|
+
* Applies time-based decay to balance adjustments
|
|
1951
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Decay.sol#L79
|
|
1952
|
+
**/
|
|
1953
|
+
const decayXD = new Opcode(Symbol("Decay.decayXD"), DecayXDArgs.CODER);
|
|
1954
|
+
|
|
1955
|
+
//#endregion
|
|
1956
|
+
//#region src/swap-vm/instructions/decay/index.ts
|
|
1957
|
+
var decay_exports = {};
|
|
1958
|
+
__export(decay_exports, {
|
|
1959
|
+
DecayXDArgs: () => DecayXDArgs,
|
|
1960
|
+
decayXD: () => decayXD
|
|
1961
|
+
});
|
|
1962
|
+
|
|
1963
|
+
//#endregion
|
|
1964
|
+
//#region src/swap-vm/instructions/limit-swap/limit-swap-direction-args-coder.ts
|
|
1965
|
+
var LimitSwapDirectionArgsCoder = class {
|
|
1966
|
+
encode(args) {
|
|
1967
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1968
|
+
builder.addUint8(args.makerDirectionLt ? 1n : 0n);
|
|
1969
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
1970
|
+
}
|
|
1971
|
+
decode(data) {
|
|
1972
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
1973
|
+
const makerDirectionLt = iter.nextUint8() !== 0n;
|
|
1974
|
+
return new LimitSwapDirectionArgs(makerDirectionLt);
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
|
|
1978
|
+
//#endregion
|
|
1979
|
+
//#region src/swap-vm/instructions/limit-swap/limit-swap-direction-args.ts
|
|
1980
|
+
/**
|
|
1981
|
+
* Arguments for limit swap instructions (limitSwap1D, limitSwapOnlyFull1D)
|
|
1982
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/LimitSwap.sol#L27
|
|
1983
|
+
**/
|
|
1984
|
+
var LimitSwapDirectionArgs = class LimitSwapDirectionArgs {
|
|
1985
|
+
static CODER = new LimitSwapDirectionArgsCoder();
|
|
1986
|
+
constructor(makerDirectionLt) {
|
|
1987
|
+
this.makerDirectionLt = makerDirectionLt;
|
|
1988
|
+
}
|
|
1989
|
+
static fromTokens(tokenIn, tokenOut) {
|
|
1990
|
+
return new LimitSwapDirectionArgs(BigInt(tokenIn.toString()) < BigInt(tokenOut.toString()));
|
|
1991
|
+
}
|
|
1992
|
+
/**
|
|
1993
|
+
* Decodes hex data into LimitSwapDirectionArgs instance
|
|
1994
|
+
**/
|
|
1995
|
+
static decode(data) {
|
|
1996
|
+
return LimitSwapDirectionArgs.CODER.decode(data);
|
|
1997
|
+
}
|
|
1998
|
+
toJSON() {
|
|
1999
|
+
return { makerDirectionLt: this.makerDirectionLt };
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
|
|
2003
|
+
//#endregion
|
|
2004
|
+
//#region src/swap-vm/instructions/limit-swap/opcodes.ts
|
|
2005
|
+
/**
|
|
2006
|
+
* Limit order swap with proportional execution
|
|
2007
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/LimitSwap.sol#L27
|
|
2008
|
+
**/
|
|
2009
|
+
const limitSwap1D = new Opcode(Symbol("LimitSwap.limitSwap1D"), LimitSwapDirectionArgs.CODER);
|
|
2010
|
+
/**
|
|
2011
|
+
* Limit order swap requiring full amount execution
|
|
2012
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/LimitSwap.sol#L44
|
|
2013
|
+
**/
|
|
2014
|
+
const limitSwapOnlyFull1D = new Opcode(Symbol("LimitSwap.limitSwapOnlyFull1D"), LimitSwapDirectionArgs.CODER);
|
|
2015
|
+
|
|
2016
|
+
//#endregion
|
|
2017
|
+
//#region src/swap-vm/instructions/limit-swap/index.ts
|
|
2018
|
+
var limit_swap_exports = {};
|
|
2019
|
+
__export(limit_swap_exports, {
|
|
2020
|
+
LimitSwapDirectionArgs: () => LimitSwapDirectionArgs,
|
|
2021
|
+
limitSwap1D: () => limitSwap1D,
|
|
2022
|
+
limitSwapOnlyFull1D: () => limitSwapOnlyFull1D
|
|
2023
|
+
});
|
|
2024
|
+
|
|
2025
|
+
//#endregion
|
|
2026
|
+
//#region src/swap-vm/instructions/min-rate/min-rate-args-coder.ts
|
|
2027
|
+
var MinRateArgsCoder = class {
|
|
2028
|
+
encode(args) {
|
|
2029
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2030
|
+
builder.addUint64(args.rateLt);
|
|
2031
|
+
builder.addUint64(args.rateGt);
|
|
2032
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
2033
|
+
}
|
|
2034
|
+
decode(data) {
|
|
2035
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2036
|
+
const rateLt = iter.nextUint64();
|
|
2037
|
+
const rateGt = iter.nextUint64();
|
|
2038
|
+
return new MinRateArgs(rateLt, rateGt);
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
|
|
2042
|
+
//#endregion
|
|
2043
|
+
//#region src/swap-vm/instructions/min-rate/min-rate-args.ts
|
|
2044
|
+
/**
|
|
2045
|
+
* Arguments for min rate instructions (requireMinRate1D, adjustMinRate1D)
|
|
2046
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/MinRate.sol#L36
|
|
2047
|
+
**/
|
|
2048
|
+
var MinRateArgs = class MinRateArgs {
|
|
2049
|
+
static CODER = new MinRateArgsCoder();
|
|
2050
|
+
/**
|
|
2051
|
+
* rateLt - minimum acceptable rate for token with lower address (uint64)
|
|
2052
|
+
* rateGt - minimum acceptable rate for token with higher address (uint64)
|
|
2053
|
+
**/
|
|
2054
|
+
constructor(rateLt, rateGt) {
|
|
2055
|
+
this.rateLt = rateLt;
|
|
2056
|
+
this.rateGt = rateGt;
|
|
2057
|
+
(0, node_assert.default)(rateLt >= 0n && rateLt <= __1inch_byte_utils.UINT_64_MAX, `Invalid rateLt: ${rateLt}. Must be a valid uint64`);
|
|
2058
|
+
(0, node_assert.default)(rateGt >= 0n && rateGt <= __1inch_byte_utils.UINT_64_MAX, `Invalid rateGt: ${rateGt}. Must be a valid uint64`);
|
|
2059
|
+
}
|
|
2060
|
+
static fromTokens(tokenA, tokenB, rateA, rateB) {
|
|
2061
|
+
if (BigInt(tokenA.toString()) < BigInt(tokenB.toString())) return new MinRateArgs(rateA, rateB);
|
|
2062
|
+
return new MinRateArgs(rateB, rateA);
|
|
2063
|
+
}
|
|
2064
|
+
/**
|
|
2065
|
+
* Decodes hex data into MinRateArgs instance
|
|
2066
|
+
**/
|
|
2067
|
+
static decode(data) {
|
|
2068
|
+
return MinRateArgs.CODER.decode(data);
|
|
2069
|
+
}
|
|
2070
|
+
toJSON() {
|
|
2071
|
+
return {
|
|
2072
|
+
rateLt: this.rateLt.toString(),
|
|
2073
|
+
rateGt: this.rateGt.toString()
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
};
|
|
2077
|
+
|
|
2078
|
+
//#endregion
|
|
2079
|
+
//#region src/swap-vm/instructions/min-rate/opcodes.ts
|
|
2080
|
+
/**
|
|
2081
|
+
* Enforces minimum exchange rate or reverts
|
|
2082
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/MinRate.sol#L36
|
|
2083
|
+
**/
|
|
2084
|
+
const requireMinRate1D = new Opcode(Symbol("MinRate.requireMinRate1D"), MinRateArgs.CODER);
|
|
2085
|
+
/**
|
|
2086
|
+
* Adjusts swap amounts to meet minimum rate if needed
|
|
2087
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/MinRate.sol#L50
|
|
2088
|
+
**/
|
|
2089
|
+
const adjustMinRate1D = new Opcode(Symbol("MinRate.adjustMinRate1D"), MinRateArgs.CODER);
|
|
2090
|
+
|
|
2091
|
+
//#endregion
|
|
2092
|
+
//#region src/swap-vm/instructions/min-rate/index.ts
|
|
2093
|
+
var min_rate_exports = {};
|
|
2094
|
+
__export(min_rate_exports, {
|
|
2095
|
+
MinRateArgs: () => MinRateArgs,
|
|
2096
|
+
adjustMinRate1D: () => adjustMinRate1D,
|
|
2097
|
+
requireMinRate1D: () => requireMinRate1D
|
|
2098
|
+
});
|
|
2099
|
+
|
|
2100
|
+
//#endregion
|
|
2101
|
+
//#region src/swap-vm/instructions/dutch-auction/dutch-auction-args-coder.ts
|
|
2102
|
+
var DutchAuctionArgsCoder = class {
|
|
2103
|
+
encode(args) {
|
|
2104
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2105
|
+
builder.addUint40(args.startTime);
|
|
2106
|
+
builder.addUint16(args.duration);
|
|
2107
|
+
builder.addUint32(args.decayFactor);
|
|
2108
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
2109
|
+
}
|
|
2110
|
+
decode(data) {
|
|
2111
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2112
|
+
const startTime = iter.nextUint40();
|
|
2113
|
+
const duration = iter.nextUint16();
|
|
2114
|
+
const decayFactor = iter.nextUint32();
|
|
2115
|
+
return new DutchAuctionArgs(startTime, duration, decayFactor);
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
|
|
2119
|
+
//#endregion
|
|
2120
|
+
//#region src/swap-vm/instructions/dutch-auction/dutch-auction-args.ts
|
|
2121
|
+
/**
|
|
2122
|
+
* @notice Dutch Auction instruction for time-based price decay with deadline
|
|
2123
|
+
* @dev Implements an exponential decay auction mechanism that works after any swap:
|
|
2124
|
+
* - Designed to be used after any swap instruction (LimitSwap, XYCSwap, etc.) which sets amounts
|
|
2125
|
+
* - Applies time-based decay to the amounts calculated by the previous swap
|
|
2126
|
+
* - Maker sells token0 and receives token1
|
|
2127
|
+
* - Price improves for taker over time through exponential decay until deadline
|
|
2128
|
+
* - Reverts if current time exceeds deadline
|
|
2129
|
+
* - Only works for 1=>0 swaps (token1 to token0)
|
|
2130
|
+
*
|
|
2131
|
+
* The decay factor determines the price reduction rate:
|
|
2132
|
+
* - 1.0e18 = no decay (constant price)
|
|
2133
|
+
* - 0.999e18 = 0.1% decay per second
|
|
2134
|
+
* - 0.99e18 = 1% decay per second
|
|
2135
|
+
* - 0.9e18 = 10% decay per second
|
|
2136
|
+
*
|
|
2137
|
+
* Example usage:
|
|
2138
|
+
* 1. Any swap instruction sets: 100 token1 → 1000 token0
|
|
2139
|
+
* 2. DutchAuction with decayFactor = 0.99e18, after 100 seconds:
|
|
2140
|
+
* - exactIn: Taker gets ~2.73x more token0 for the same token1
|
|
2141
|
+
* - exactOut: Taker needs only ~36.6% of initial token1
|
|
2142
|
+
* 3. After deadline, the auction expires and cannot be executed
|
|
2143
|
+
*
|
|
2144
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/DutchAuction.sol#L66
|
|
2145
|
+
*/
|
|
2146
|
+
var DutchAuctionArgs = class DutchAuctionArgs {
|
|
2147
|
+
static CODER = new DutchAuctionArgsCoder();
|
|
2148
|
+
/**
|
|
2149
|
+
* startTime - auction start time (uint40)
|
|
2150
|
+
* duration - auction duration in seconds (uint16)
|
|
2151
|
+
* decayFactor - price decay per second, 1e18 = no decay (uint32)
|
|
2152
|
+
**/
|
|
2153
|
+
constructor(startTime, duration, decayFactor) {
|
|
2154
|
+
this.startTime = startTime;
|
|
2155
|
+
this.duration = duration;
|
|
2156
|
+
this.decayFactor = decayFactor;
|
|
2157
|
+
(0, node_assert.default)(startTime >= 0n && startTime <= __1inch_byte_utils.UINT_40_MAX, `Invalid startTime: ${startTime}. Must be a valid uint40`);
|
|
2158
|
+
(0, node_assert.default)(duration >= 0n && duration <= __1inch_byte_utils.UINT_16_MAX, `Invalid duration: ${duration}. Must be a valid uint16`);
|
|
2159
|
+
(0, node_assert.default)(decayFactor >= 0n && decayFactor <= __1inch_byte_utils.UINT_32_MAX, `Invalid decayFactor: ${decayFactor}. Must be a valid uint32`);
|
|
2160
|
+
(0, node_assert.default)(decayFactor < 1e18, `Decay factor should be less than 1e18: ${decayFactor}`);
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Decodes hex data into DutchAuctionArgs instance
|
|
2164
|
+
**/
|
|
2165
|
+
static decode(data) {
|
|
2166
|
+
return DutchAuctionArgs.CODER.decode(data);
|
|
2167
|
+
}
|
|
2168
|
+
toJSON() {
|
|
2169
|
+
return {
|
|
2170
|
+
startTime: this.startTime.toString(),
|
|
2171
|
+
duration: this.duration.toString(),
|
|
2172
|
+
decayFactor: this.decayFactor.toString()
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
};
|
|
2176
|
+
|
|
2177
|
+
//#endregion
|
|
2178
|
+
//#region src/swap-vm/instructions/dutch-auction/opcodes.ts
|
|
2179
|
+
/**
|
|
2180
|
+
* Dutch auction with time-based decay on amountIn
|
|
2181
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/DutchAuction.sol#L75
|
|
2182
|
+
**/
|
|
2183
|
+
const dutchAuctionBalanceIn1D = new Opcode(Symbol("DutchAuction.dutchAuctionBalanceIn1D"), DutchAuctionArgs.CODER);
|
|
2184
|
+
/**
|
|
2185
|
+
* Dutch auction with time-based decay on amountOut
|
|
2186
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/DutchAuction.sol#L85
|
|
2187
|
+
**/
|
|
2188
|
+
const dutchAuctionBalanceOut1D = new Opcode(Symbol("DutchAuction.dutchAuctionBalanceOut1D"), DutchAuctionArgs.CODER);
|
|
2189
|
+
|
|
2190
|
+
//#endregion
|
|
2191
|
+
//#region src/swap-vm/instructions/dutch-auction/index.ts
|
|
2192
|
+
var dutch_auction_exports = {};
|
|
2193
|
+
__export(dutch_auction_exports, {
|
|
2194
|
+
DutchAuctionArgs: () => DutchAuctionArgs,
|
|
2195
|
+
dutchAuctionBalanceIn1D: () => dutchAuctionBalanceIn1D,
|
|
2196
|
+
dutchAuctionBalanceOut1D: () => dutchAuctionBalanceOut1D
|
|
2197
|
+
});
|
|
2198
|
+
|
|
2199
|
+
//#endregion
|
|
2200
|
+
//#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.ts
|
|
2201
|
+
var OraclePriceAdjusterArgsCoder = class {
|
|
2202
|
+
encode(args) {
|
|
2203
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2204
|
+
builder.addUint64(args.maxPriceDecay);
|
|
2205
|
+
builder.addUint16(args.maxStaleness);
|
|
2206
|
+
builder.addUint8(args.oracleDecimals);
|
|
2207
|
+
builder.addAddress(args.oracleAddress.toString());
|
|
2208
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
2209
|
+
}
|
|
2210
|
+
decode(data) {
|
|
2211
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
2212
|
+
const maxPriceDecay = iter.nextUint64();
|
|
2213
|
+
const maxStaleness = iter.nextUint16();
|
|
2214
|
+
const oracleDecimals = iter.nextUint8();
|
|
2215
|
+
const oracleAddress = new __1inch_sdk_core.Address(iter.nextAddress());
|
|
2216
|
+
return new OraclePriceAdjusterArgs(BigInt(maxPriceDecay), BigInt(maxStaleness), BigInt(oracleDecimals), oracleAddress);
|
|
2217
|
+
}
|
|
2218
|
+
};
|
|
2219
|
+
|
|
2220
|
+
//#endregion
|
|
2221
|
+
//#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.ts
|
|
2222
|
+
/**
|
|
2223
|
+
* @notice Oracle Price Adjuster instruction for dynamic price adjustment based on Chainlink price feeds
|
|
2224
|
+
* @dev Adjusts swap prices to match Chainlink oracle prices within safe bounds:
|
|
2225
|
+
* - Works only for 1=>0 swaps (token1 to token0), compatible with LimitSwap and other swap instructions
|
|
2226
|
+
* - Fetches current market price from a Chainlink oracle (AggregatorV3Interface)
|
|
2227
|
+
* - Adjusts the swap price towards the oracle price within maxPriceDecay limits
|
|
2228
|
+
* - Ensures the adjustment is always favorable for the taker
|
|
2229
|
+
* - Handles different decimal places from Chainlink oracles (e.g., 8 decimals for USD prices)
|
|
2230
|
+
*
|
|
2231
|
+
* This creates adaptive orders that automatically track market prices while maintaining
|
|
2232
|
+
* safety bounds to prevent excessive slippage or manipulation.
|
|
2233
|
+
*
|
|
2234
|
+
* Example usage:
|
|
2235
|
+
* 1. LimitSwap sets base price: 1 ETH for 3000 USDC
|
|
2236
|
+
* 2. OraclePriceAdjuster with Chainlink ETH/USD oracle: 1 ETH = 3100 USD, maxPriceDecay=0.95e18 (5% max)
|
|
2237
|
+
* 3. exactIn: Taker gets more ETH (up to 5% improvement)
|
|
2238
|
+
* 4. exactOut: Taker pays less USDC (up to 5% discount)
|
|
2239
|
+
*
|
|
2240
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
|
|
2241
|
+
*/
|
|
2242
|
+
var OraclePriceAdjusterArgs = class OraclePriceAdjusterArgs {
|
|
2243
|
+
static CODER = new OraclePriceAdjusterArgsCoder();
|
|
2244
|
+
/**
|
|
2245
|
+
* maxPriceDecay - maximum price decay coefficient (uint64)
|
|
2246
|
+
* maxStaleness - maximum allowed oracle data staleness in seconds (uint16
|
|
2247
|
+
* oracleDecimals - decimals used by the oracle (uint8)
|
|
2248
|
+
* oracleAddress - address of the Chainlink price oracle contract
|
|
2249
|
+
**/
|
|
2250
|
+
constructor(maxPriceDecay, maxStaleness, oracleDecimals, oracleAddress) {
|
|
2251
|
+
this.maxPriceDecay = maxPriceDecay;
|
|
2252
|
+
this.maxStaleness = maxStaleness;
|
|
2253
|
+
this.oracleDecimals = oracleDecimals;
|
|
2254
|
+
this.oracleAddress = oracleAddress;
|
|
2255
|
+
(0, node_assert.default)(maxPriceDecay >= 0n && maxPriceDecay <= __1inch_byte_utils.UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
|
|
2256
|
+
(0, node_assert.default)(maxPriceDecay < 1e18, `Max price decay should be less than 1e18: ${maxPriceDecay}`);
|
|
2257
|
+
(0, node_assert.default)(maxStaleness >= 0n && maxStaleness <= __1inch_byte_utils.UINT_16_MAX, `Invalid maxStaleness: ${maxStaleness}. Must be a valid uint16`);
|
|
2258
|
+
(0, node_assert.default)(oracleDecimals >= 0n && oracleDecimals <= __1inch_byte_utils.UINT_8_MAX, `Invalid oracleDecimals: ${oracleDecimals}. Must be a valid uint8`);
|
|
2259
|
+
}
|
|
2260
|
+
/**
|
|
2261
|
+
* Decodes hex data into OraclePriceAdjusterArgs instance
|
|
2262
|
+
**/
|
|
2263
|
+
static decode(data) {
|
|
2264
|
+
return OraclePriceAdjusterArgs.CODER.decode(data);
|
|
2265
|
+
}
|
|
2266
|
+
toJSON() {
|
|
2267
|
+
return {
|
|
2268
|
+
maxPriceDecay: this.maxPriceDecay.toString(),
|
|
2269
|
+
maxStaleness: this.maxStaleness.toString(),
|
|
2270
|
+
oracleDecimals: this.oracleDecimals.toString(),
|
|
2271
|
+
oracleAddress: this.oracleAddress.toString()
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2274
|
+
};
|
|
2275
|
+
|
|
2276
|
+
//#endregion
|
|
2277
|
+
//#region src/swap-vm/instructions/oracle-price-adjuster/opcodes.ts
|
|
2278
|
+
/**
|
|
2279
|
+
* Adjusts swap prices based on Chainlink oracle feeds
|
|
2280
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
|
|
2281
|
+
**/
|
|
2282
|
+
const oraclePriceAdjuster1D = new Opcode(Symbol("OraclePriceAdjuster.oraclePriceAdjuster1D"), OraclePriceAdjusterArgs.CODER);
|
|
2283
|
+
|
|
2284
|
+
//#endregion
|
|
2285
|
+
//#region src/swap-vm/instructions/oracle-price-adjuster/index.ts
|
|
2286
|
+
var oracle_price_adjuster_exports = {};
|
|
2287
|
+
__export(oracle_price_adjuster_exports, {
|
|
2288
|
+
OraclePriceAdjusterArgs: () => OraclePriceAdjusterArgs,
|
|
2289
|
+
oraclePriceAdjuster1D: () => oraclePriceAdjuster1D
|
|
2290
|
+
});
|
|
2291
|
+
|
|
2292
|
+
//#endregion
|
|
2293
|
+
//#region src/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.ts
|
|
2294
|
+
var BaseFeeAdjusterArgsCoder = class {
|
|
2295
|
+
encode(args) {
|
|
2296
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2297
|
+
builder.addUint64(args.baseGasPrice);
|
|
2298
|
+
builder.addUint96(args.ethToToken1Price);
|
|
2299
|
+
builder.addUint24(args.gasAmount);
|
|
2300
|
+
builder.addUint64(args.maxPriceDecay);
|
|
2301
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
2302
|
+
}
|
|
2303
|
+
decode(data) {
|
|
2304
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2305
|
+
const baseGasPrice = iter.nextUint64();
|
|
2306
|
+
const ethToToken1Price = iter.nextUint96();
|
|
2307
|
+
const gasAmount = iter.nextUint24();
|
|
2308
|
+
const maxPriceDecay = iter.nextUint64();
|
|
2309
|
+
return new BaseFeeAdjusterArgs(baseGasPrice, ethToToken1Price, gasAmount, maxPriceDecay);
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2312
|
+
|
|
2313
|
+
//#endregion
|
|
2314
|
+
//#region src/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args.ts
|
|
2315
|
+
/**
|
|
2316
|
+
* @notice Base Fee Gas Price Adjuster instruction for dynamic price adjustment based on network gas costs
|
|
2317
|
+
* @dev Adjusts swap prices based on current gas conditions to compensate for transaction costs:
|
|
2318
|
+
* - Works only for 1=>0 swaps (token1 to token0), compatible with LimitSwap and DutchAuction
|
|
2319
|
+
* - When gas price exceeds base level, maker improves the price to compensate taker for gas costs
|
|
2320
|
+
* - The adjustment is proportional to the difference between current and base gas prices
|
|
2321
|
+
* - Maximum adjustment is limited by maxPriceDecay parameter
|
|
2322
|
+
*
|
|
2323
|
+
* This creates adaptive limit orders that automatically become more attractive during high gas periods,
|
|
2324
|
+
* ensuring execution even when transaction costs are elevated.
|
|
2325
|
+
*
|
|
2326
|
+
* Example usage:
|
|
2327
|
+
* 1. LimitSwap sets base price: 1 ETH for 3000 USDC
|
|
2328
|
+
* 2. BaseFeeAdjuster with baseGasPrice=20 gwei, current=100 gwei
|
|
2329
|
+
* 3. Extra cost = 80 gwei * 150k gas * 3000 USDC/ETH = 36 USDC
|
|
2330
|
+
* 4. With maxPriceDecay=0.99e18 (1% max), final price: 1 ETH for 2970 USDC
|
|
2331
|
+
*
|
|
2332
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/BaseFeeAdjuster.sol#L75
|
|
2333
|
+
*/
|
|
2334
|
+
var BaseFeeAdjusterArgs = class BaseFeeAdjusterArgs {
|
|
2335
|
+
static CODER = new BaseFeeAdjusterArgsCoder();
|
|
2336
|
+
/**
|
|
2337
|
+
* baseGasPrice - base gas price for comparison (uint64)
|
|
2338
|
+
* ethToToken1Price - ETH price in token1 units, e.g.,
|
|
2339
|
+
* 3000e18 for 1 ETH = 3000 USDC (uint96)
|
|
2340
|
+
* gasAmount - gas amount to compensate for (uint24)
|
|
2341
|
+
**/
|
|
2342
|
+
constructor(baseGasPrice, ethToToken1Price, gasAmount, maxPriceDecay) {
|
|
2343
|
+
this.baseGasPrice = baseGasPrice;
|
|
2344
|
+
this.ethToToken1Price = ethToToken1Price;
|
|
2345
|
+
this.gasAmount = gasAmount;
|
|
2346
|
+
this.maxPriceDecay = maxPriceDecay;
|
|
2347
|
+
(0, node_assert.default)(baseGasPrice >= 0n && baseGasPrice <= __1inch_byte_utils.UINT_64_MAX, `Invalid baseGasPrice: ${baseGasPrice}. Must be a valid uint64`);
|
|
2348
|
+
(0, node_assert.default)(ethToToken1Price >= 0n && ethToToken1Price <= __1inch_byte_utils.UINT_96_MAX, `Invalid ethToToken1Price: ${ethToToken1Price}. Must be a valid uint96`);
|
|
2349
|
+
(0, node_assert.default)(gasAmount >= 0n && gasAmount <= __1inch_byte_utils.UINT_24_MAX, `Invalid gasAmount: ${gasAmount}. Must be a valid uint24`);
|
|
2350
|
+
(0, node_assert.default)(maxPriceDecay >= 0n && maxPriceDecay <= __1inch_byte_utils.UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
|
|
2351
|
+
}
|
|
2352
|
+
/**
|
|
2353
|
+
* Decodes hex data into BaseFeeAdjusterArgs instance
|
|
2354
|
+
**/
|
|
2355
|
+
static decode(data) {
|
|
2356
|
+
return BaseFeeAdjusterArgs.CODER.decode(data);
|
|
2357
|
+
}
|
|
2358
|
+
toJSON() {
|
|
2359
|
+
return {
|
|
2360
|
+
baseGasPrice: this.baseGasPrice.toString(),
|
|
2361
|
+
ethToToken1Price: this.ethToToken1Price.toString(),
|
|
2362
|
+
gasAmount: this.gasAmount.toString(),
|
|
2363
|
+
maxPriceDecay: this.maxPriceDecay.toString()
|
|
2364
|
+
};
|
|
2365
|
+
}
|
|
2366
|
+
};
|
|
2367
|
+
|
|
2368
|
+
//#endregion
|
|
2369
|
+
//#region src/swap-vm/instructions/base-fee-adjuster/opcodes.ts
|
|
2370
|
+
/**
|
|
2371
|
+
* Adjusts swap prices based on network gas costs
|
|
2372
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/BaseFeeAdjuster.sol#L75
|
|
2373
|
+
**/
|
|
2374
|
+
const baseFeeAdjuster1D = new Opcode(Symbol("BaseFeeAdjuster.baseFeeAdjuster1D"), BaseFeeAdjusterArgs.CODER);
|
|
2375
|
+
|
|
2376
|
+
//#endregion
|
|
2377
|
+
//#region src/swap-vm/instructions/base-fee-adjuster/index.ts
|
|
2378
|
+
var base_fee_adjuster_exports = {};
|
|
2379
|
+
__export(base_fee_adjuster_exports, {
|
|
2380
|
+
BaseFeeAdjusterArgs: () => BaseFeeAdjusterArgs,
|
|
2381
|
+
baseFeeAdjuster1D: () => baseFeeAdjuster1D
|
|
2382
|
+
});
|
|
2383
|
+
|
|
2384
|
+
//#endregion
|
|
2385
|
+
//#region src/swap-vm/instructions/twap-swap/twap-swap-args-coder.ts
|
|
2386
|
+
var TWAPSwapArgsCoder = class {
|
|
2387
|
+
encode(args) {
|
|
2388
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2389
|
+
builder.addUint256(args.balanceIn);
|
|
2390
|
+
builder.addUint256(args.balanceOut);
|
|
2391
|
+
builder.addUint256(args.startTime);
|
|
2392
|
+
builder.addUint256(args.duration);
|
|
2393
|
+
builder.addUint256(args.priceBumpAfterIlliquidity);
|
|
2394
|
+
builder.addUint256(args.minTradeAmountOut);
|
|
2395
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
2396
|
+
}
|
|
2397
|
+
decode(data) {
|
|
2398
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2399
|
+
const balanceIn = iter.nextUint256();
|
|
2400
|
+
const balanceOut = iter.nextUint256();
|
|
2401
|
+
const startTime = iter.nextUint256();
|
|
2402
|
+
const duration = iter.nextUint256();
|
|
2403
|
+
const priceBumpAfterIlliquidity = iter.nextUint256();
|
|
2404
|
+
const minTradeAmountOut = iter.nextUint256();
|
|
2405
|
+
return new TWAPSwapArgs(balanceIn, balanceOut, startTime, duration, priceBumpAfterIlliquidity, minTradeAmountOut);
|
|
2406
|
+
}
|
|
2407
|
+
};
|
|
2408
|
+
|
|
2409
|
+
//#endregion
|
|
2410
|
+
//#region src/swap-vm/instructions/twap-swap/twap-swap-args.ts
|
|
2411
|
+
/**
|
|
2412
|
+
* @notice TWAP Hook with exponential dutch auction and illiquidity handling
|
|
2413
|
+
* @dev Implements a TWAP (Time-Weighted Average Price) selling strategy with the following features:
|
|
2414
|
+
* - Linear liquidity unlocking over time
|
|
2415
|
+
* - Exponential price decay (dutch auction) for better price discovery
|
|
2416
|
+
* - Automatic price bump after periods of insufficient liquidity
|
|
2417
|
+
* - Minimum trade size enforcement during TWAP duration
|
|
2418
|
+
*
|
|
2419
|
+
* Minimum Trade Size (minTradeAmountOut):
|
|
2420
|
+
* The minimum trade size protects against gas cost impact on execution price.
|
|
2421
|
+
* It should be set 1000x+ larger than the expected transaction fees on the deployment network.
|
|
2422
|
+
*
|
|
2423
|
+
* For example:
|
|
2424
|
+
* - Ethereum mainnet with $50 gas cost → minTradeAmountOut should be $50,000+
|
|
2425
|
+
* - Arbitrum/Optimism with $0.50 gas cost → minTradeAmountOut should be $500+
|
|
2426
|
+
* - BSC/Polygon with $0.05 gas cost → minTradeAmountOut should be $50+
|
|
2427
|
+
*
|
|
2428
|
+
* This ensures gas costs remain negligible (<0.1%) relative to trade value.
|
|
2429
|
+
*
|
|
2430
|
+
* Price Bump Configuration Guidelines:
|
|
2431
|
+
*
|
|
2432
|
+
* The priceBumpAfterIlliquidity compensates for mandatory waiting periods due to linear unlocking.
|
|
2433
|
+
* Time to unlock minTradeAmountOut = (minTradeAmountOut / balance0) * duration
|
|
2434
|
+
*
|
|
2435
|
+
* Examples:
|
|
2436
|
+
* - minTradeAmountOut = 0.1% of balance0, duration = 24h → 14.4 min to unlock each min trade
|
|
2437
|
+
* Recommended bump: 1.05e18 - 1.10e18 (5-10%)
|
|
2438
|
+
*
|
|
2439
|
+
* - minTradeAmountOut = 1% of balance0, duration = 24h → 14.4 min to unlock each min trade
|
|
2440
|
+
* Recommended bump: 1.10e18 - 1.20e18 (10-20%)
|
|
2441
|
+
*
|
|
2442
|
+
* - minTradeAmountOut = 5% of balance0, duration = 24h → 1.2 hours to unlock each min trade
|
|
2443
|
+
* Recommended bump: 1.30e18 - 1.50e18 (30-50%)
|
|
2444
|
+
*
|
|
2445
|
+
* - minTradeAmountOut = 10% of balance0, duration = 24h → 2.4 hours to unlock each min trade
|
|
2446
|
+
* Recommended bump: 1.50e18 - 2.00e18 (50-100%)
|
|
2447
|
+
*
|
|
2448
|
+
* Additional factors to consider:
|
|
2449
|
+
* - Network gas costs: Higher gas requires larger bumps
|
|
2450
|
+
* - Pair volatility: Volatile pairs need larger bumps to compensate for price risk
|
|
2451
|
+
* - Market depth: Thin markets may need higher bumps to attract arbitrageurs
|
|
2452
|
+
*
|
|
2453
|
+
* The bump should ensure profitability after the mandatory waiting period.
|
|
2454
|
+
*
|
|
2455
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/TWAPSwap.sol#L104
|
|
2456
|
+
*/
|
|
2457
|
+
var TWAPSwapArgs = class TWAPSwapArgs {
|
|
2458
|
+
static CODER = new TWAPSwapArgsCoder();
|
|
2459
|
+
/**
|
|
2460
|
+
* balanceIn - expected amount of token1 for initial price (uint256)
|
|
2461
|
+
* balanceOut - total amount of token0 for TWAP (uint256)
|
|
2462
|
+
* startTime - TWAP start time (uint256)
|
|
2463
|
+
* duration - TWAP duration (uint256)
|
|
2464
|
+
* priceBumpAfterIlliquidity - price jump when liquidity insufficient, e.g. 1.10e18 = +10% (uint256)
|
|
2465
|
+
* minTradeAmountOut - minimum trade size for token0 (uint256)
|
|
2466
|
+
**/
|
|
2467
|
+
constructor(balanceIn, balanceOut, startTime, duration, priceBumpAfterIlliquidity, minTradeAmountOut) {
|
|
2468
|
+
this.balanceIn = balanceIn;
|
|
2469
|
+
this.balanceOut = balanceOut;
|
|
2470
|
+
this.startTime = startTime;
|
|
2471
|
+
this.duration = duration;
|
|
2472
|
+
this.priceBumpAfterIlliquidity = priceBumpAfterIlliquidity;
|
|
2473
|
+
this.minTradeAmountOut = minTradeAmountOut;
|
|
2474
|
+
(0, node_assert.default)(balanceIn >= 0n && balanceIn <= __1inch_byte_utils.UINT_256_MAX, `Invalid balanceIn: ${balanceIn}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2475
|
+
(0, node_assert.default)(balanceOut >= 0n && balanceOut <= __1inch_byte_utils.UINT_256_MAX, `Invalid balanceOut: ${balanceOut}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2476
|
+
(0, node_assert.default)(startTime >= 0n && startTime <= __1inch_byte_utils.UINT_256_MAX, `Invalid startTime: ${startTime}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2477
|
+
(0, node_assert.default)(duration >= 0n && duration <= __1inch_byte_utils.UINT_256_MAX, `Invalid duration: ${duration}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2478
|
+
(0, node_assert.default)(priceBumpAfterIlliquidity >= 0n && priceBumpAfterIlliquidity <= __1inch_byte_utils.UINT_256_MAX, `Invalid priceBumpAfterIlliquidity: ${priceBumpAfterIlliquidity}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2479
|
+
(0, node_assert.default)(minTradeAmountOut >= 0n && minTradeAmountOut <= __1inch_byte_utils.UINT_256_MAX, `Invalid minTradeAmountOut: ${minTradeAmountOut}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2480
|
+
}
|
|
2481
|
+
/**
|
|
2482
|
+
* Decodes hex data into TWAPSwapArgs instance
|
|
2483
|
+
**/
|
|
2484
|
+
static decode(data) {
|
|
2485
|
+
return TWAPSwapArgs.CODER.decode(data);
|
|
2486
|
+
}
|
|
2487
|
+
toJSON() {
|
|
2488
|
+
return {
|
|
2489
|
+
balanceIn: this.balanceIn.toString(),
|
|
2490
|
+
balanceOut: this.balanceOut.toString(),
|
|
2491
|
+
startTime: this.startTime.toString(),
|
|
2492
|
+
duration: this.duration.toString(),
|
|
2493
|
+
priceBumpAfterIlliquidity: this.priceBumpAfterIlliquidity.toString(),
|
|
2494
|
+
minTradeAmountOut: this.minTradeAmountOut.toString()
|
|
2495
|
+
};
|
|
2496
|
+
}
|
|
2497
|
+
};
|
|
2498
|
+
|
|
2499
|
+
//#endregion
|
|
2500
|
+
//#region src/swap-vm/instructions/twap-swap/opcodes.ts
|
|
2501
|
+
/**
|
|
2502
|
+
* TWAP trading with exponential dutch auction and illiquidity handling
|
|
2503
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/TWAPSwap.sol#L104
|
|
2504
|
+
**/
|
|
2505
|
+
const twap = new Opcode(Symbol("TWAPSwap.twap"), TWAPSwapArgs.CODER);
|
|
2506
|
+
|
|
2507
|
+
//#endregion
|
|
2508
|
+
//#region src/swap-vm/instructions/twap-swap/index.ts
|
|
2509
|
+
var twap_swap_exports = {};
|
|
2510
|
+
__export(twap_swap_exports, {
|
|
2511
|
+
TWAPSwapArgs: () => TWAPSwapArgs,
|
|
2512
|
+
twap: () => twap
|
|
2513
|
+
});
|
|
2514
|
+
|
|
2515
|
+
//#endregion
|
|
2516
|
+
//#region src/swap-vm/instructions/fee/flat-fee-args-coder.ts
|
|
2517
|
+
var FlatFeeArgsCoder = class {
|
|
2518
|
+
encode(args) {
|
|
2519
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2520
|
+
builder.addUint32(args.fee);
|
|
2521
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
2522
|
+
}
|
|
2523
|
+
decode(data) {
|
|
2524
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2525
|
+
const fee = iter.nextUint32();
|
|
2526
|
+
return new FlatFeeArgs(fee);
|
|
2527
|
+
}
|
|
2528
|
+
};
|
|
2529
|
+
|
|
2530
|
+
//#endregion
|
|
2531
|
+
//#region src/swap-vm/instructions/fee/flat-fee-args.ts
|
|
2532
|
+
const FEE_100_PERCENT$1 = 1e9;
|
|
2533
|
+
/**
|
|
2534
|
+
* Arguments for flat fee instructions (flatFeeXD, flatFeeAmountInXD, flatFeeAmountOutXD, progressiveFeeXD)
|
|
2535
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L66
|
|
2536
|
+
**/
|
|
2537
|
+
var FlatFeeArgs = class FlatFeeArgs {
|
|
2538
|
+
static CODER = new FlatFeeArgsCoder();
|
|
2539
|
+
constructor(fee) {
|
|
2540
|
+
this.fee = fee;
|
|
2541
|
+
(0, node_assert.default)(fee >= 0n && fee <= __1inch_byte_utils.UINT_32_MAX, `Invalid fee: ${fee}. Must be a valid uint32`);
|
|
2542
|
+
(0, node_assert.default)(fee <= BigInt(FEE_100_PERCENT$1), `Fee out of range: ${fee}. Must be <= ${FEE_100_PERCENT$1}`);
|
|
2543
|
+
}
|
|
2544
|
+
/**
|
|
2545
|
+
* Decodes hex data into FlatFeeArgs instance
|
|
2546
|
+
**/
|
|
2547
|
+
static decode(data) {
|
|
2548
|
+
return FlatFeeArgs.CODER.decode(data);
|
|
2549
|
+
}
|
|
2550
|
+
/**
|
|
2551
|
+
* Creates a FlatFeeArgs instance from percentage
|
|
2552
|
+
* @param percent - Fee as percentage (e.g., 1 for 1%, 0.1 for 0.1%)
|
|
2553
|
+
* @returns FlatFeeArgs instance
|
|
2554
|
+
*/
|
|
2555
|
+
static fromPercent(percent) {
|
|
2556
|
+
return FlatFeeArgs.fromBps(percent * 100);
|
|
2557
|
+
}
|
|
2558
|
+
/**
|
|
2559
|
+
* Creates a FlatFeeArgs instance from basis points
|
|
2560
|
+
* @param bps - Fee in basis points (10000 bps = 100%)
|
|
2561
|
+
* @returns FlatFeeArgs instance
|
|
2562
|
+
*/
|
|
2563
|
+
static fromBps(bps) {
|
|
2564
|
+
const fee = BigInt(bps * 1e5);
|
|
2565
|
+
return new FlatFeeArgs(fee);
|
|
2566
|
+
}
|
|
2567
|
+
toJSON() {
|
|
2568
|
+
return { fee: this.fee.toString() };
|
|
2569
|
+
}
|
|
2570
|
+
};
|
|
2571
|
+
|
|
2572
|
+
//#endregion
|
|
2573
|
+
//#region src/swap-vm/instructions/fee/protocol-fee-args-coder.ts
|
|
2574
|
+
var ProtocolFeeArgsCoder = class {
|
|
2575
|
+
encode(args) {
|
|
2576
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2577
|
+
builder.addUint32(args.fee);
|
|
2578
|
+
builder.addAddress(args.to.toString());
|
|
2579
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
2580
|
+
}
|
|
2581
|
+
decode(data) {
|
|
2582
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
2583
|
+
const fee = iter.nextUint32();
|
|
2584
|
+
const to = new __1inch_sdk_core.Address(iter.nextAddress());
|
|
2585
|
+
return new ProtocolFeeArgs(BigInt(fee), to);
|
|
2586
|
+
}
|
|
2587
|
+
};
|
|
2588
|
+
|
|
2589
|
+
//#endregion
|
|
2590
|
+
//#region src/swap-vm/instructions/fee/protocol-fee-args.ts
|
|
2591
|
+
const FEE_100_PERCENT = 1e9;
|
|
2592
|
+
/**
|
|
2593
|
+
* Arguments for protocol fee instructions (protocolFeeAmountOutXD, aquaProtocolFeeAmountOutXD)
|
|
2594
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L102
|
|
2595
|
+
**/
|
|
2596
|
+
var ProtocolFeeArgs = class ProtocolFeeArgs {
|
|
2597
|
+
static CODER = new ProtocolFeeArgsCoder();
|
|
2598
|
+
/**
|
|
2599
|
+
* fee - 1e9 = 100% (uint32)
|
|
2600
|
+
* to - address to send pulled tokens to (20 bytes)
|
|
2601
|
+
**/
|
|
2602
|
+
constructor(fee, to) {
|
|
2603
|
+
this.fee = fee;
|
|
2604
|
+
this.to = to;
|
|
2605
|
+
(0, node_assert.default)(fee >= 0n && fee <= __1inch_byte_utils.UINT_32_MAX, `Invalid fee: ${fee}. Must be a valid uint32`);
|
|
2606
|
+
(0, node_assert.default)(fee <= BigInt(FEE_100_PERCENT), `Fee out of range: ${fee}. Must be <= ${FEE_100_PERCENT}`);
|
|
2607
|
+
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Decodes hex data into ProtocolFeeArgs instance
|
|
2610
|
+
**/
|
|
2611
|
+
static decode(data) {
|
|
2612
|
+
return ProtocolFeeArgs.CODER.decode(data);
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Creates a ProtocolFeeArgs instance from percentage
|
|
2616
|
+
* @param percent - Fee as percentage (e.g., 1 for 1%, 0.1 for 0.1%)
|
|
2617
|
+
* @param to - Address to receive the protocol fee
|
|
2618
|
+
* @returns ProtocolFeeArgs instance
|
|
2619
|
+
*/
|
|
2620
|
+
static fromPercent(percent, to) {
|
|
2621
|
+
return ProtocolFeeArgs.fromBps(percent * 100, to);
|
|
2622
|
+
}
|
|
2623
|
+
/**
|
|
2624
|
+
* Creates a ProtocolFeeArgs instance from basis points
|
|
2625
|
+
* @param bps - Fee in basis points (10000 bps = 100%)
|
|
2626
|
+
* @param to - Address to receive the protocol fee
|
|
2627
|
+
* @returns ProtocolFeeArgs instance
|
|
2628
|
+
*/
|
|
2629
|
+
static fromBps(bps, to) {
|
|
2630
|
+
const fee = BigInt(bps * 1e5);
|
|
2631
|
+
return new ProtocolFeeArgs(fee, to);
|
|
2632
|
+
}
|
|
2633
|
+
toJSON() {
|
|
2634
|
+
return {
|
|
2635
|
+
fee: this.fee.toString(),
|
|
2636
|
+
to: this.to.toString()
|
|
2637
|
+
};
|
|
2638
|
+
}
|
|
2639
|
+
};
|
|
2640
|
+
|
|
2641
|
+
//#endregion
|
|
2642
|
+
//#region src/swap-vm/instructions/fee/opcodes.ts
|
|
2643
|
+
/**
|
|
2644
|
+
* Applies fee to amountIn
|
|
2645
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L66
|
|
2646
|
+
**/
|
|
2647
|
+
const flatFeeAmountInXD = new Opcode(Symbol("Fee.flatFeeAmountInXD"), FlatFeeArgs.CODER);
|
|
2648
|
+
/**
|
|
2649
|
+
* Applies fee to amountOut
|
|
2650
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L72
|
|
2651
|
+
**/
|
|
2652
|
+
const flatFeeAmountOutXD = new Opcode(Symbol("Fee.flatFeeAmountOutXD"), FlatFeeArgs.CODER);
|
|
2653
|
+
/**
|
|
2654
|
+
* Applies progressive fee to amountIn
|
|
2655
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L78
|
|
2656
|
+
**/
|
|
2657
|
+
const progressiveFeeInXD = new Opcode(Symbol("Fee.progressiveFeeInXD"), FlatFeeArgs.CODER);
|
|
2658
|
+
/**
|
|
2659
|
+
* Applies progressive fee to amountOut
|
|
2660
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L106
|
|
2661
|
+
**/
|
|
2662
|
+
const progressiveFeeOutXD = new Opcode(Symbol("Fee.progressiveFeeOutXD"), FlatFeeArgs.CODER);
|
|
2663
|
+
/**
|
|
2664
|
+
* Applies protocol fee to amountOut with direct transfer
|
|
2665
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L102
|
|
2666
|
+
**/
|
|
2667
|
+
const protocolFeeAmountOutXD = new Opcode(Symbol("Fee.protocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
|
|
2668
|
+
/**
|
|
2669
|
+
* Applies protocol fee to amountOut through Aqua protocol
|
|
2670
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L110
|
|
2671
|
+
**/
|
|
2672
|
+
const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("Fee.aquaProtocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
|
|
2673
|
+
|
|
2674
|
+
//#endregion
|
|
2675
|
+
//#region src/swap-vm/instructions/fee/index.ts
|
|
2676
|
+
var fee_exports = {};
|
|
2677
|
+
__export(fee_exports, {
|
|
2678
|
+
FlatFeeArgs: () => FlatFeeArgs,
|
|
2679
|
+
ProtocolFeeArgs: () => ProtocolFeeArgs,
|
|
2680
|
+
aquaProtocolFeeAmountOutXD: () => aquaProtocolFeeAmountOutXD,
|
|
2681
|
+
flatFeeAmountInXD: () => flatFeeAmountInXD,
|
|
2682
|
+
flatFeeAmountOutXD: () => flatFeeAmountOutXD,
|
|
2683
|
+
progressiveFeeInXD: () => progressiveFeeInXD,
|
|
2684
|
+
progressiveFeeOutXD: () => progressiveFeeOutXD,
|
|
2685
|
+
protocolFeeAmountOutXD: () => protocolFeeAmountOutXD
|
|
2686
|
+
});
|
|
2687
|
+
|
|
2688
|
+
//#endregion
|
|
2689
|
+
//#region src/swap-vm/instructions/extruction/extruction-args-coder.ts
|
|
2690
|
+
var ExtructionArgsCoder = class {
|
|
2691
|
+
encode(args) {
|
|
2692
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2693
|
+
builder.addAddress(args.target.toString());
|
|
2694
|
+
builder.addBytes(args.extructionArgs.toString());
|
|
2695
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
2696
|
+
}
|
|
2697
|
+
decode(data) {
|
|
2698
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
2699
|
+
const target = new __1inch_sdk_core.Address(iter.nextAddress());
|
|
2700
|
+
const extructionArgs = new __1inch_sdk_core.HexString(iter.rest());
|
|
2701
|
+
return new ExtructionArgs(target, extructionArgs);
|
|
2702
|
+
}
|
|
2703
|
+
};
|
|
2704
|
+
|
|
2705
|
+
//#endregion
|
|
2706
|
+
//#region src/swap-vm/instructions/extruction/extruction-args.ts
|
|
2707
|
+
/**
|
|
2708
|
+
* Arguments for extruction instruction to call external contract logic
|
|
2709
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Extruction.sol#L33
|
|
2710
|
+
**/
|
|
2711
|
+
var ExtructionArgs = class ExtructionArgs {
|
|
2712
|
+
static CODER = new ExtructionArgsCoder();
|
|
2713
|
+
/**
|
|
2714
|
+
* target - External contract address (20 bytes)
|
|
2715
|
+
* extructionArgs - Arguments to pass to external contract (variable)
|
|
2716
|
+
**/
|
|
2717
|
+
constructor(target, extructionArgs) {
|
|
2718
|
+
this.target = target;
|
|
2719
|
+
this.extructionArgs = extructionArgs;
|
|
2720
|
+
}
|
|
2721
|
+
/**
|
|
2722
|
+
* Decodes hex data into ExtructionArgs instance
|
|
2723
|
+
**/
|
|
2724
|
+
static decode(data) {
|
|
2725
|
+
return ExtructionArgs.CODER.decode(data);
|
|
2726
|
+
}
|
|
2727
|
+
toJSON() {
|
|
2728
|
+
return {
|
|
2729
|
+
target: this.target.toString(),
|
|
2730
|
+
extructionArgs: this.extructionArgs.toString()
|
|
2731
|
+
};
|
|
2732
|
+
}
|
|
2733
|
+
};
|
|
2734
|
+
|
|
2735
|
+
//#endregion
|
|
2736
|
+
//#region src/swap-vm/instructions/extruction/opcodes.ts
|
|
2737
|
+
/**
|
|
2738
|
+
* Calls external contract to perform custom logic, potentially modifying swap state
|
|
2739
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Extruction.sol#L33
|
|
2740
|
+
**/
|
|
2741
|
+
const extruction = new Opcode(Symbol("Extruction.extruction"), ExtructionArgs.CODER);
|
|
2742
|
+
|
|
2743
|
+
//#endregion
|
|
2744
|
+
//#region src/swap-vm/instructions/extruction/index.ts
|
|
2745
|
+
var extruction_exports = {};
|
|
2746
|
+
__export(extruction_exports, {
|
|
2747
|
+
ExtructionArgs: () => ExtructionArgs,
|
|
2748
|
+
extruction: () => extruction
|
|
2749
|
+
});
|
|
2750
|
+
|
|
2751
|
+
//#endregion
|
|
2752
|
+
//#region src/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.ts
|
|
2753
|
+
var StableSwap2DArgsCoder = class {
|
|
2754
|
+
encode(args) {
|
|
2755
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2756
|
+
builder.addUint32(args.fee);
|
|
2757
|
+
builder.addUint32(args.A);
|
|
2758
|
+
builder.addUint256(args.rateLt);
|
|
2759
|
+
builder.addUint256(args.rateGt);
|
|
2760
|
+
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
2761
|
+
}
|
|
2762
|
+
decode(data) {
|
|
2763
|
+
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2764
|
+
const fee = iter.nextUint32();
|
|
2765
|
+
const A = iter.nextUint32();
|
|
2766
|
+
const rateLt = iter.nextUint256();
|
|
2767
|
+
const rateGt = iter.nextUint256();
|
|
2768
|
+
return new StableSwap2DArgs(fee, A, rateLt, rateGt);
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
|
|
2772
|
+
//#endregion
|
|
2773
|
+
//#region src/swap-vm/instructions/stable-swap/stable-swap-2d-args.ts
|
|
2774
|
+
/**
|
|
2775
|
+
* Arguments for stableSwap2D instruction for stablecoin optimized swaps
|
|
2776
|
+
**/
|
|
2777
|
+
var StableSwap2DArgs = class StableSwap2DArgs {
|
|
2778
|
+
static CODER = new StableSwap2DArgsCoder();
|
|
2779
|
+
/**
|
|
2780
|
+
* fee - swap fee in 1e10 (uint32)
|
|
2781
|
+
* A - amplification coefficient (uint32)
|
|
2782
|
+
* rateLt - rate for token with lower address (uint256)
|
|
2783
|
+
* rateGt - rate for token with higher address (uint256)
|
|
2784
|
+
**/
|
|
2785
|
+
constructor(fee, A, rateLt, rateGt) {
|
|
2786
|
+
this.fee = fee;
|
|
2787
|
+
this.A = A;
|
|
2788
|
+
this.rateLt = rateLt;
|
|
2789
|
+
this.rateGt = rateGt;
|
|
2790
|
+
(0, node_assert.default)(fee >= 0n && fee <= __1inch_byte_utils.UINT_32_MAX, `Invalid fee: ${fee}`);
|
|
2791
|
+
(0, node_assert.default)(A >= 0n && A <= __1inch_byte_utils.UINT_32_MAX, `Invalid A: ${A}`);
|
|
2792
|
+
(0, node_assert.default)(rateLt > 0n && rateLt <= __1inch_byte_utils.UINT_256_MAX, `Invalid rateLt: ${rateLt}. Must be positive and <= UINT_256_MAX`);
|
|
2793
|
+
(0, node_assert.default)(rateGt > 0n && rateGt <= __1inch_byte_utils.UINT_256_MAX, `Invalid rateGt: ${rateGt}. Must be positive and <= UINT_256_MAX`);
|
|
2794
|
+
}
|
|
2795
|
+
static fromTokens(fee, a, tokenA, tokenB, rateA, rateB) {
|
|
2796
|
+
if (BigInt(tokenA.toString()) < BigInt(tokenB.toString())) return new StableSwap2DArgs(fee, a, rateA, rateB);
|
|
2797
|
+
return new StableSwap2DArgs(fee, a, rateB, rateA);
|
|
2798
|
+
}
|
|
2799
|
+
/**
|
|
2800
|
+
* Decodes hex data into StableSwap2DArgs instance
|
|
2801
|
+
**/
|
|
2802
|
+
static decode(data) {
|
|
2803
|
+
return StableSwap2DArgs.CODER.decode(data);
|
|
2804
|
+
}
|
|
2805
|
+
toJSON() {
|
|
2806
|
+
return {
|
|
2807
|
+
fee: this.fee.toString(),
|
|
2808
|
+
A: this.A.toString(),
|
|
2809
|
+
rateLt: this.rateLt.toString(),
|
|
2810
|
+
rateGt: this.rateGt.toString()
|
|
2811
|
+
};
|
|
2812
|
+
}
|
|
2813
|
+
};
|
|
2814
|
+
|
|
2815
|
+
//#endregion
|
|
2816
|
+
//#region src/swap-vm/instructions/stable-swap/opcodes.ts
|
|
2817
|
+
/**
|
|
2818
|
+
* Stablecoin optimized swap using StableSwap algorithm (Curve-style)
|
|
2819
|
+
**/
|
|
2820
|
+
const stableSwap2D = new Opcode(Symbol("StableSwap.stableSwap2D"), StableSwap2DArgs.CODER);
|
|
2821
|
+
|
|
2822
|
+
//#endregion
|
|
2823
|
+
//#region src/swap-vm/instructions/stable-swap/index.ts
|
|
2824
|
+
var stable_swap_exports = {};
|
|
2825
|
+
__export(stable_swap_exports, {
|
|
2826
|
+
StableSwap2DArgs: () => StableSwap2DArgs,
|
|
2827
|
+
stableSwap2D: () => stableSwap2D
|
|
2828
|
+
});
|
|
2829
|
+
|
|
2830
|
+
//#endregion
|
|
2831
|
+
//#region src/swap-vm/instructions/index.ts
|
|
2832
|
+
var instructions_exports = {};
|
|
2833
|
+
__export(instructions_exports, {
|
|
2834
|
+
EMPTY_OPCODE: () => EMPTY_OPCODE,
|
|
2835
|
+
_allInstructions: () => _allInstructions,
|
|
2836
|
+
aquaInstructions: () => aquaInstructions,
|
|
2837
|
+
balances: () => balances_exports,
|
|
2838
|
+
baseFeeAdjuster: () => base_fee_adjuster_exports,
|
|
2839
|
+
concentrate: () => concentrate_exports,
|
|
2840
|
+
controls: () => controls_exports,
|
|
2841
|
+
decay: () => decay_exports,
|
|
2842
|
+
dutchAuction: () => dutch_auction_exports,
|
|
2843
|
+
extruction: () => extruction_exports,
|
|
2844
|
+
fee: () => fee_exports,
|
|
2845
|
+
invalidators: () => invalidators_exports,
|
|
2846
|
+
limitSwap: () => limit_swap_exports,
|
|
2847
|
+
minRate: () => min_rate_exports,
|
|
2848
|
+
oraclePriceAdjuster: () => oracle_price_adjuster_exports,
|
|
2849
|
+
stableSwap: () => stable_swap_exports,
|
|
2850
|
+
twapSwap: () => twap_swap_exports,
|
|
2851
|
+
xycSwap: () => xyc_swap_exports
|
|
2852
|
+
});
|
|
2853
|
+
/**
|
|
2854
|
+
* Regular opcodes array - matching SwapVM contract exactly (44 opcodes)
|
|
2855
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/opcodes/Opcodes.sol#L46
|
|
2856
|
+
*/
|
|
2857
|
+
const _allInstructions = [
|
|
2858
|
+
EMPTY_OPCODE,
|
|
2859
|
+
EMPTY_OPCODE,
|
|
2860
|
+
EMPTY_OPCODE,
|
|
2861
|
+
EMPTY_OPCODE,
|
|
2862
|
+
EMPTY_OPCODE,
|
|
2863
|
+
EMPTY_OPCODE,
|
|
2864
|
+
EMPTY_OPCODE,
|
|
2865
|
+
EMPTY_OPCODE,
|
|
2866
|
+
EMPTY_OPCODE,
|
|
2867
|
+
EMPTY_OPCODE,
|
|
2868
|
+
jump,
|
|
2869
|
+
jumpIfTokenIn,
|
|
2870
|
+
jumpIfTokenOut,
|
|
2871
|
+
deadline,
|
|
2872
|
+
onlyTakerTokenBalanceNonZero,
|
|
2873
|
+
onlyTakerTokenBalanceGte,
|
|
2874
|
+
onlyTakerTokenSupplyShareGte,
|
|
2875
|
+
staticBalancesXD,
|
|
2876
|
+
dynamicBalancesXD,
|
|
2877
|
+
invalidateBit1D,
|
|
2878
|
+
invalidateTokenIn1D,
|
|
2879
|
+
invalidateTokenOut1D,
|
|
2880
|
+
xycSwapXD,
|
|
2881
|
+
concentrateGrowLiquidityXD,
|
|
2882
|
+
concentrateGrowLiquidity2D,
|
|
2883
|
+
decayXD,
|
|
2884
|
+
limitSwap1D,
|
|
2885
|
+
limitSwapOnlyFull1D,
|
|
2886
|
+
requireMinRate1D,
|
|
2887
|
+
adjustMinRate1D,
|
|
2888
|
+
dutchAuctionBalanceIn1D,
|
|
2889
|
+
dutchAuctionBalanceOut1D,
|
|
2890
|
+
oraclePriceAdjuster1D,
|
|
2891
|
+
baseFeeAdjuster1D,
|
|
2892
|
+
twap,
|
|
2893
|
+
extruction,
|
|
2894
|
+
salt,
|
|
2895
|
+
flatFeeAmountInXD,
|
|
2896
|
+
flatFeeAmountOutXD,
|
|
2897
|
+
progressiveFeeInXD,
|
|
2898
|
+
progressiveFeeOutXD,
|
|
2899
|
+
protocolFeeAmountOutXD,
|
|
2900
|
+
aquaProtocolFeeAmountOutXD
|
|
2901
|
+
];
|
|
2902
|
+
/**
|
|
2903
|
+
* Aqua opcodes array - matching AquaSwapVM contract (29 opcodes)
|
|
2904
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/opcodes/AquaOpcodes.sol#L28
|
|
2905
|
+
*/
|
|
2906
|
+
const aquaInstructions = [
|
|
2907
|
+
EMPTY_OPCODE,
|
|
2908
|
+
EMPTY_OPCODE,
|
|
2909
|
+
EMPTY_OPCODE,
|
|
2910
|
+
EMPTY_OPCODE,
|
|
2911
|
+
EMPTY_OPCODE,
|
|
2912
|
+
EMPTY_OPCODE,
|
|
2913
|
+
EMPTY_OPCODE,
|
|
2914
|
+
EMPTY_OPCODE,
|
|
2915
|
+
EMPTY_OPCODE,
|
|
2916
|
+
EMPTY_OPCODE,
|
|
2917
|
+
jump,
|
|
2918
|
+
jumpIfTokenIn,
|
|
2919
|
+
jumpIfTokenOut,
|
|
2920
|
+
deadline,
|
|
2921
|
+
onlyTakerTokenBalanceNonZero,
|
|
2922
|
+
onlyTakerTokenBalanceGte,
|
|
2923
|
+
onlyTakerTokenSupplyShareGte,
|
|
2924
|
+
xycSwapXD,
|
|
2925
|
+
concentrateGrowLiquidityXD,
|
|
2926
|
+
concentrateGrowLiquidity2D,
|
|
2927
|
+
decayXD,
|
|
2928
|
+
salt,
|
|
2929
|
+
flatFeeAmountInXD,
|
|
2930
|
+
flatFeeAmountOutXD,
|
|
2931
|
+
progressiveFeeInXD,
|
|
2932
|
+
progressiveFeeOutXD,
|
|
2933
|
+
protocolFeeAmountOutXD,
|
|
2934
|
+
aquaProtocolFeeAmountOutXD
|
|
2935
|
+
];
|
|
2936
|
+
|
|
2937
|
+
//#endregion
|
|
2938
|
+
//#region src/swap-vm/instructions/debug/debug-empty-args.ts
|
|
2939
|
+
var DebugEmptyArgsCoder = class {
|
|
2940
|
+
encode(_args) {
|
|
2941
|
+
return __1inch_sdk_core.HexString.EMPTY;
|
|
2942
|
+
}
|
|
2943
|
+
decode(_data) {
|
|
2944
|
+
return new DebugEmptyArgs();
|
|
2945
|
+
}
|
|
2946
|
+
};
|
|
2947
|
+
/**
|
|
2948
|
+
* Debug empty instruction arguments - used for debugging purposes
|
|
2949
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Debug.sol
|
|
2950
|
+
**/
|
|
2951
|
+
var DebugEmptyArgs = class DebugEmptyArgs {
|
|
2952
|
+
static CODER = new DebugEmptyArgsCoder();
|
|
2953
|
+
/**
|
|
2954
|
+
* Decodes hex data into DebugEmptyArgs instance
|
|
2955
|
+
**/
|
|
2956
|
+
static decode(_data) {
|
|
2957
|
+
return DebugEmptyArgs.CODER.decode(_data);
|
|
2958
|
+
}
|
|
2959
|
+
toJSON() {
|
|
2960
|
+
return null;
|
|
2961
|
+
}
|
|
2962
|
+
};
|
|
2963
|
+
|
|
2964
|
+
//#endregion
|
|
2965
|
+
//#region src/swap-vm/instructions/debug/debug-args.ts
|
|
2966
|
+
/**
|
|
2967
|
+
* Base class for all debug instruction arguments
|
|
2968
|
+
* Debug instructions don't have parameters, they just print/log state
|
|
2969
|
+
*/
|
|
2970
|
+
var DebugArgs = class {
|
|
2971
|
+
toJSON() {
|
|
2972
|
+
return null;
|
|
2973
|
+
}
|
|
2974
|
+
};
|
|
2975
|
+
|
|
2976
|
+
//#endregion
|
|
2977
|
+
//#region src/swap-vm/instructions/debug/print-swap-registers.ts
|
|
2978
|
+
var PrintSwapRegistersArgsCoder = class {
|
|
2979
|
+
encode(_args) {
|
|
2980
|
+
return __1inch_sdk_core.HexString.EMPTY;
|
|
2981
|
+
}
|
|
2982
|
+
decode(_data) {
|
|
2983
|
+
return new PrintSwapRegistersArgs();
|
|
2984
|
+
}
|
|
2985
|
+
};
|
|
2986
|
+
/**
|
|
2987
|
+
* Debug instruction to print swap registers
|
|
2988
|
+
* @see Debug._printSwapRegisters in Solidity
|
|
2989
|
+
*/
|
|
2990
|
+
var PrintSwapRegistersArgs = class PrintSwapRegistersArgs extends DebugArgs {
|
|
2991
|
+
static CODER = new PrintSwapRegistersArgsCoder();
|
|
2992
|
+
static decode(_data) {
|
|
2993
|
+
return PrintSwapRegistersArgs.CODER.decode(_data);
|
|
2994
|
+
}
|
|
2995
|
+
};
|
|
2996
|
+
|
|
2997
|
+
//#endregion
|
|
2998
|
+
//#region src/swap-vm/instructions/debug/print-swap-query.ts
|
|
2999
|
+
var PrintSwapQueryArgsCoder = class {
|
|
3000
|
+
encode(_args) {
|
|
3001
|
+
return __1inch_sdk_core.HexString.EMPTY;
|
|
3002
|
+
}
|
|
3003
|
+
decode(_data) {
|
|
3004
|
+
return new PrintSwapQueryArgs();
|
|
3005
|
+
}
|
|
3006
|
+
};
|
|
3007
|
+
/**
|
|
3008
|
+
* Debug instruction to print swap query information
|
|
3009
|
+
* @see Debug._printSwapQuery in Solidity
|
|
3010
|
+
*/
|
|
3011
|
+
var PrintSwapQueryArgs = class PrintSwapQueryArgs extends DebugArgs {
|
|
3012
|
+
static CODER = new PrintSwapQueryArgsCoder();
|
|
3013
|
+
static decode(_data) {
|
|
3014
|
+
return PrintSwapQueryArgs.CODER.decode(_data);
|
|
3015
|
+
}
|
|
3016
|
+
};
|
|
3017
|
+
|
|
3018
|
+
//#endregion
|
|
3019
|
+
//#region src/swap-vm/instructions/debug/print-context.ts
|
|
3020
|
+
var PrintContextArgsCoder = class {
|
|
3021
|
+
encode(_args) {
|
|
3022
|
+
return __1inch_sdk_core.HexString.EMPTY;
|
|
3023
|
+
}
|
|
3024
|
+
decode(_data) {
|
|
3025
|
+
return new PrintContextArgs();
|
|
3026
|
+
}
|
|
3027
|
+
};
|
|
3028
|
+
/**
|
|
3029
|
+
* Debug instruction to print execution context
|
|
3030
|
+
* @see Debug._printContext in Solidity
|
|
3031
|
+
*/
|
|
3032
|
+
var PrintContextArgs = class PrintContextArgs extends DebugArgs {
|
|
3033
|
+
static CODER = new PrintContextArgsCoder();
|
|
3034
|
+
static decode(_data) {
|
|
3035
|
+
return PrintContextArgs.CODER.decode(_data);
|
|
3036
|
+
}
|
|
3037
|
+
};
|
|
3038
|
+
|
|
3039
|
+
//#endregion
|
|
3040
|
+
//#region src/swap-vm/instructions/debug/print-amount-for-swap.ts
|
|
3041
|
+
var PrintAmountForSwapArgsCoder = class {
|
|
3042
|
+
encode(_args) {
|
|
3043
|
+
return __1inch_sdk_core.HexString.EMPTY;
|
|
3044
|
+
}
|
|
3045
|
+
decode(_data) {
|
|
3046
|
+
return new PrintAmountForSwapArgs();
|
|
3047
|
+
}
|
|
3048
|
+
};
|
|
3049
|
+
/**
|
|
3050
|
+
* Debug instruction to print amount for swap
|
|
3051
|
+
* @see Debug._printAmountForSwap in Solidity
|
|
3052
|
+
*/
|
|
3053
|
+
var PrintAmountForSwapArgs = class PrintAmountForSwapArgs extends DebugArgs {
|
|
3054
|
+
static CODER = new PrintAmountForSwapArgsCoder();
|
|
3055
|
+
static decode(_data) {
|
|
3056
|
+
return PrintAmountForSwapArgs.CODER.decode(_data);
|
|
3057
|
+
}
|
|
3058
|
+
};
|
|
3059
|
+
|
|
3060
|
+
//#endregion
|
|
3061
|
+
//#region src/swap-vm/instructions/debug/print-free-memory-pointer.ts
|
|
3062
|
+
var PrintFreeMemoryPointerArgsCoder = class {
|
|
3063
|
+
encode(_args) {
|
|
3064
|
+
return __1inch_sdk_core.HexString.EMPTY;
|
|
3065
|
+
}
|
|
3066
|
+
decode(_data) {
|
|
3067
|
+
return new PrintFreeMemoryPointerArgs();
|
|
3068
|
+
}
|
|
3069
|
+
};
|
|
3070
|
+
/**
|
|
3071
|
+
* Debug instruction to print free memory pointer
|
|
3072
|
+
* @see Debug._printFreeMemoryPointer in Solidity
|
|
3073
|
+
*/
|
|
3074
|
+
var PrintFreeMemoryPointerArgs = class PrintFreeMemoryPointerArgs extends DebugArgs {
|
|
3075
|
+
static CODER = new PrintFreeMemoryPointerArgsCoder();
|
|
3076
|
+
static decode(_data) {
|
|
3077
|
+
return PrintFreeMemoryPointerArgs.CODER.decode(_data);
|
|
3078
|
+
}
|
|
3079
|
+
};
|
|
3080
|
+
|
|
3081
|
+
//#endregion
|
|
3082
|
+
//#region src/swap-vm/instructions/debug/print-gas-left.ts
|
|
3083
|
+
var PrintGasLeftArgsCoder = class {
|
|
3084
|
+
encode(_args) {
|
|
3085
|
+
return __1inch_sdk_core.HexString.EMPTY;
|
|
3086
|
+
}
|
|
3087
|
+
decode(_data) {
|
|
3088
|
+
return new PrintGasLeftArgs();
|
|
3089
|
+
}
|
|
3090
|
+
};
|
|
3091
|
+
/**
|
|
3092
|
+
* Debug instruction to print remaining gas
|
|
3093
|
+
* @see Debug._printGasLeft in Solidity
|
|
3094
|
+
*/
|
|
3095
|
+
var PrintGasLeftArgs = class PrintGasLeftArgs extends DebugArgs {
|
|
3096
|
+
static CODER = new PrintGasLeftArgsCoder();
|
|
3097
|
+
static decode(_data) {
|
|
3098
|
+
return PrintGasLeftArgs.CODER.decode(_data);
|
|
3099
|
+
}
|
|
3100
|
+
};
|
|
3101
|
+
|
|
3102
|
+
//#endregion
|
|
3103
|
+
//#region src/swap-vm/instructions/debug/opcodes.ts
|
|
3104
|
+
/**
|
|
3105
|
+
* Debug empty opcode - placeholder
|
|
3106
|
+
*/
|
|
3107
|
+
const debugEmpty = new Opcode(Symbol("Debug.Empty"), DebugEmptyArgs.CODER);
|
|
3108
|
+
const printSwapRegisters = new Opcode(Symbol("Debug.printSwapRegisters"), PrintSwapRegistersArgs.CODER);
|
|
3109
|
+
const printSwapQuery = new Opcode(Symbol("Debug.printSwapQuery"), PrintSwapQueryArgs.CODER);
|
|
3110
|
+
const printContext = new Opcode(Symbol("Debug.printContext"), PrintContextArgs.CODER);
|
|
3111
|
+
const printAmountForSwap = new Opcode(Symbol("debug.printAmountForSwap"), PrintAmountForSwapArgs.CODER);
|
|
3112
|
+
const printFreeMemoryPointer = new Opcode(Symbol("Debug.printFreeMemoryPointer"), PrintFreeMemoryPointerArgs.CODER);
|
|
3113
|
+
const printGasLeft = new Opcode(Symbol("Debug.printGasLeft"), PrintGasLeftArgs.CODER);
|
|
3114
|
+
|
|
3115
|
+
//#endregion
|
|
3116
|
+
//#region src/swap-vm/programs/regular-program-builder.ts
|
|
3117
|
+
var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
3118
|
+
constructor() {
|
|
3119
|
+
super([..._allInstructions]);
|
|
3120
|
+
}
|
|
3121
|
+
static decode(program) {
|
|
3122
|
+
return new RegularProgramBuilder().decode(program);
|
|
3123
|
+
}
|
|
3124
|
+
/**
|
|
3125
|
+
* Enables debug mode for the program
|
|
3126
|
+
* WARNING: Debug instructions will throw an error if debug mode is not enabled
|
|
3127
|
+
*/
|
|
3128
|
+
withDebug() {
|
|
3129
|
+
this.ixsSet[0] = printSwapRegisters;
|
|
3130
|
+
this.ixsSet[1] = printSwapQuery;
|
|
3131
|
+
this.ixsSet[2] = printContext;
|
|
3132
|
+
this.ixsSet[3] = printAmountForSwap;
|
|
3133
|
+
this.ixsSet[4] = printFreeMemoryPointer;
|
|
3134
|
+
this.ixsSet[5] = printGasLeft;
|
|
3135
|
+
return this;
|
|
3136
|
+
}
|
|
3137
|
+
/**
|
|
3138
|
+
* Sets initial token balances for the swap program
|
|
3139
|
+
**/
|
|
3140
|
+
staticBalancesXD(data) {
|
|
3141
|
+
super.add(staticBalancesXD.createIx(new BalancesArgs(data.tokenBalances)));
|
|
3142
|
+
return this;
|
|
3143
|
+
}
|
|
3144
|
+
/**
|
|
3145
|
+
* Reads token balances from program data or contract storage
|
|
3146
|
+
**/
|
|
3147
|
+
dynamicBalancesXD(data) {
|
|
3148
|
+
super.add(dynamicBalancesXD.createIx(new BalancesArgs(data.tokenBalances)));
|
|
3149
|
+
return this;
|
|
3150
|
+
}
|
|
3151
|
+
/**
|
|
3152
|
+
* Unconditional jump to specified program counter
|
|
3153
|
+
**/
|
|
3154
|
+
jump(data) {
|
|
3155
|
+
super.add(jump.createIx(new JumpArgs(data.nextPC)));
|
|
3156
|
+
return this;
|
|
3157
|
+
}
|
|
3158
|
+
/**
|
|
3159
|
+
* Jumps if tokenIn is the specified token
|
|
3160
|
+
**/
|
|
3161
|
+
jumpIfTokenIn(data) {
|
|
3162
|
+
super.add(jumpIfTokenIn.createIx(new JumpIfTokenArgs(data.tokenTail, data.nextPC)));
|
|
3163
|
+
return this;
|
|
3164
|
+
}
|
|
3165
|
+
/**
|
|
3166
|
+
* Jumps if tokenOut is the specified token
|
|
3167
|
+
**/
|
|
3168
|
+
jumpIfTokenOut(data) {
|
|
3169
|
+
super.add(jumpIfTokenOut.createIx(new JumpIfTokenArgs(data.tokenTail, data.nextPC)));
|
|
3170
|
+
return this;
|
|
3171
|
+
}
|
|
3172
|
+
/**
|
|
3173
|
+
* Reverts if the deadline has been reached
|
|
3174
|
+
**/
|
|
3175
|
+
deadline(data) {
|
|
3176
|
+
super.add(deadline.createIx(new DeadlineArgs(data.deadline)));
|
|
3177
|
+
return this;
|
|
3178
|
+
}
|
|
3179
|
+
/**
|
|
3180
|
+
* Requires taker to hold any amount of specified token (supports NFTs)
|
|
3181
|
+
**/
|
|
3182
|
+
onlyTakerTokenBalanceNonZero(data) {
|
|
3183
|
+
super.add(onlyTakerTokenBalanceNonZero.createIx(new OnlyTakerTokenBalanceNonZeroArgs(data.token)));
|
|
3184
|
+
return this;
|
|
3185
|
+
}
|
|
3186
|
+
/**
|
|
3187
|
+
* Requires taker to hold at least specified amount of token
|
|
3188
|
+
**/
|
|
3189
|
+
onlyTakerTokenBalanceGte(data) {
|
|
3190
|
+
super.add(onlyTakerTokenBalanceGte.createIx(new OnlyTakerTokenBalanceGteArgs(data.token, data.minAmount)));
|
|
3191
|
+
return this;
|
|
3192
|
+
}
|
|
3193
|
+
/**
|
|
3194
|
+
* Requires taker to hold at least specified share of token's total supply
|
|
3195
|
+
**/
|
|
3196
|
+
onlyTakerTokenSupplyShareGte(data) {
|
|
3197
|
+
super.add(onlyTakerTokenSupplyShareGte.createIx(new OnlyTakerTokenSupplyShareGteArgs(data.token, data.minShareE18)));
|
|
3198
|
+
return this;
|
|
3199
|
+
}
|
|
3200
|
+
/**
|
|
3201
|
+
* No-op instruction used to add uniqueness to order hashes (prevents replay attacks)
|
|
3202
|
+
**/
|
|
3203
|
+
salt(data) {
|
|
3204
|
+
super.add(salt.createIx(new SaltArgs(data.salt)));
|
|
3205
|
+
return this;
|
|
3206
|
+
}
|
|
3207
|
+
/**
|
|
3208
|
+
* Invalidates a specific bit index for order uniqueness
|
|
3209
|
+
**/
|
|
3210
|
+
invalidateBit1D(data) {
|
|
3211
|
+
super.add(invalidateBit1D.createIx(new InvalidateBit1DArgs(data.bitIndex)));
|
|
3212
|
+
return this;
|
|
3213
|
+
}
|
|
3214
|
+
/**
|
|
3215
|
+
* Invalidates order by token input to prevent re-use
|
|
3216
|
+
**/
|
|
3217
|
+
invalidateTokenIn1D() {
|
|
3218
|
+
super.add(invalidateTokenIn1D.createIx(new InvalidateTokenIn1DArgs()));
|
|
3219
|
+
return this;
|
|
3220
|
+
}
|
|
3221
|
+
/**
|
|
3222
|
+
* Invalidates order by token output to prevent re-use
|
|
3223
|
+
**/
|
|
3224
|
+
invalidateTokenOut1D() {
|
|
3225
|
+
super.add(invalidateTokenOut1D.createIx(new InvalidateTokenOut1DArgs()));
|
|
3226
|
+
return this;
|
|
3227
|
+
}
|
|
3228
|
+
/**
|
|
3229
|
+
* Basic swap using constant product formula (x*y=k)
|
|
3230
|
+
**/
|
|
3231
|
+
xycSwapXD() {
|
|
3232
|
+
super.add(xycSwapXD.createIx(new XycSwapXDArgs()));
|
|
3233
|
+
return this;
|
|
3234
|
+
}
|
|
3235
|
+
/**
|
|
3236
|
+
* Concentrates liquidity within price bounds for multiple tokens
|
|
3237
|
+
**/
|
|
3238
|
+
concentrateGrowLiquidityXD(data) {
|
|
3239
|
+
super.add(concentrateGrowLiquidityXD.createIx(new ConcentrateGrowLiquidityXDArgs(data.tokenDeltas)));
|
|
3240
|
+
return this;
|
|
3241
|
+
}
|
|
3242
|
+
/**
|
|
3243
|
+
* Concentrates liquidity within price bounds for two tokens
|
|
3244
|
+
**/
|
|
3245
|
+
concentrateGrowLiquidity2D(data) {
|
|
3246
|
+
super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.deltaLt, data.deltaGt)));
|
|
3247
|
+
return this;
|
|
3248
|
+
}
|
|
3249
|
+
/**
|
|
3250
|
+
* Applies time-based decay to balance adjustments
|
|
3251
|
+
**/
|
|
3252
|
+
decayXD(data) {
|
|
3253
|
+
super.add(decayXD.createIx(new DecayXDArgs(data.decayPeriod)));
|
|
3254
|
+
return this;
|
|
3255
|
+
}
|
|
3256
|
+
/**
|
|
3257
|
+
* Limit order swap with proportional execution
|
|
3258
|
+
**/
|
|
3259
|
+
limitSwap1D(data) {
|
|
3260
|
+
super.add(limitSwap1D.createIx(new LimitSwapDirectionArgs(data.makerDirectionLt)));
|
|
3261
|
+
return this;
|
|
3262
|
+
}
|
|
3263
|
+
/**
|
|
3264
|
+
* Limit order swap requiring full amount execution
|
|
3265
|
+
**/
|
|
3266
|
+
limitSwapOnlyFull1D(data) {
|
|
3267
|
+
super.add(limitSwapOnlyFull1D.createIx(new LimitSwapDirectionArgs(data.makerDirectionLt)));
|
|
3268
|
+
return this;
|
|
3269
|
+
}
|
|
3270
|
+
/**
|
|
3271
|
+
* Enforces minimum exchange rate or reverts
|
|
3272
|
+
**/
|
|
3273
|
+
requireMinRate1D(data) {
|
|
3274
|
+
super.add(requireMinRate1D.createIx(new MinRateArgs(data.rateLt, data.rateGt)));
|
|
3275
|
+
return this;
|
|
3276
|
+
}
|
|
3277
|
+
/**
|
|
3278
|
+
* Adjusts swap amounts to meet minimum rate if needed
|
|
3279
|
+
**/
|
|
3280
|
+
adjustMinRate1D(data) {
|
|
3281
|
+
super.add(adjustMinRate1D.createIx(new MinRateArgs(data.rateLt, data.rateGt)));
|
|
3282
|
+
return this;
|
|
3283
|
+
}
|
|
3284
|
+
/**
|
|
3285
|
+
* Dutch auction with time-based decay on amountIn
|
|
3286
|
+
**/
|
|
3287
|
+
dutchAuctionBalanceIn1D(data) {
|
|
3288
|
+
super.add(dutchAuctionBalanceIn1D.createIx(new DutchAuctionArgs(data.startTime, data.duration, data.decayFactor)));
|
|
3289
|
+
return this;
|
|
3290
|
+
}
|
|
3291
|
+
/**
|
|
3292
|
+
* Dutch auction with time-based decay on amountOut
|
|
3293
|
+
**/
|
|
3294
|
+
dutchAuctionBalanceOut1D(data) {
|
|
3295
|
+
super.add(dutchAuctionBalanceOut1D.createIx(new DutchAuctionArgs(data.startTime, data.duration, data.decayFactor)));
|
|
3296
|
+
return this;
|
|
3297
|
+
}
|
|
3298
|
+
/**
|
|
3299
|
+
* Adjusts swap prices based on Chainlink oracle feeds
|
|
3300
|
+
**/
|
|
3301
|
+
oraclePriceAdjuster1D(data) {
|
|
3302
|
+
super.add(oraclePriceAdjuster1D.createIx(new OraclePriceAdjusterArgs(data.maxPriceDecay, data.maxStaleness, data.oracleDecimals, data.oracleAddress)));
|
|
3303
|
+
return this;
|
|
3304
|
+
}
|
|
3305
|
+
/**
|
|
3306
|
+
* Adjusts swap prices based on network gas costs
|
|
3307
|
+
**/
|
|
3308
|
+
baseFeeAdjuster1D(data) {
|
|
3309
|
+
super.add(baseFeeAdjuster1D.createIx(new BaseFeeAdjusterArgs(data.baseGasPrice, data.ethToToken1Price, data.gasAmount, data.maxPriceDecay)));
|
|
3310
|
+
return this;
|
|
3311
|
+
}
|
|
3312
|
+
/**
|
|
3313
|
+
* TWAP trading with exponential dutch auction and illiquidity handling
|
|
3314
|
+
**/
|
|
3315
|
+
twap(data) {
|
|
3316
|
+
super.add(twap.createIx(new TWAPSwapArgs(data.balanceIn, data.balanceOut, data.startTime, data.duration, data.priceBumpAfterIlliquidity, data.minTradeAmountOut)));
|
|
3317
|
+
return this;
|
|
3318
|
+
}
|
|
3319
|
+
/**
|
|
3320
|
+
* Calls external contract to perform custom logic
|
|
3321
|
+
**/
|
|
3322
|
+
extruction(data) {
|
|
3323
|
+
super.add(extruction.createIx(new ExtructionArgs(data.target, data.extructionArgs)));
|
|
3324
|
+
return this;
|
|
3325
|
+
}
|
|
3326
|
+
/**
|
|
3327
|
+
* Applies fee to amountIn
|
|
3328
|
+
**/
|
|
3329
|
+
flatFeeAmountInXD(data) {
|
|
3330
|
+
super.add(flatFeeAmountInXD.createIx(new FlatFeeArgs(data.fee)));
|
|
3331
|
+
return this;
|
|
3332
|
+
}
|
|
3333
|
+
/**
|
|
3334
|
+
* Applies fee to amountOut
|
|
3335
|
+
**/
|
|
3336
|
+
flatFeeAmountOutXD(data) {
|
|
3337
|
+
super.add(flatFeeAmountOutXD.createIx(new FlatFeeArgs(data.fee)));
|
|
3338
|
+
return this;
|
|
3339
|
+
}
|
|
3340
|
+
/**
|
|
3341
|
+
* Applies progressive fee to amountIn
|
|
3342
|
+
**/
|
|
3343
|
+
progressiveFeeInXD(data) {
|
|
3344
|
+
super.add(progressiveFeeInXD.createIx(new FlatFeeArgs(data.fee)));
|
|
3345
|
+
return this;
|
|
3346
|
+
}
|
|
3347
|
+
/**
|
|
3348
|
+
* Applies progressive fee to amountOut
|
|
3349
|
+
**/
|
|
3350
|
+
progressiveFeeOutXD(data) {
|
|
3351
|
+
super.add(progressiveFeeOutXD.createIx(new FlatFeeArgs(data.fee)));
|
|
3352
|
+
return this;
|
|
3353
|
+
}
|
|
3354
|
+
/**
|
|
3355
|
+
* Applies protocol fee to amountOut with direct transfer
|
|
3356
|
+
**/
|
|
3357
|
+
protocolFeeAmountOutXD(data) {
|
|
3358
|
+
super.add(protocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3359
|
+
return this;
|
|
3360
|
+
}
|
|
3361
|
+
/**
|
|
3362
|
+
* Applies protocol fee to amountOut through Aqua protocol
|
|
3363
|
+
**/
|
|
3364
|
+
aquaProtocolFeeAmountOutXD(data) {
|
|
3365
|
+
super.add(aquaProtocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3366
|
+
return this;
|
|
3367
|
+
}
|
|
3368
|
+
/**
|
|
3369
|
+
* DEBUG: Prints current swap registers (amounts and tokens)
|
|
3370
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3371
|
+
*/
|
|
3372
|
+
debugPrintSwapRegisters() {
|
|
3373
|
+
super.add(printSwapRegisters.createIx(new PrintSwapRegistersArgs()));
|
|
3374
|
+
return this;
|
|
3375
|
+
}
|
|
3376
|
+
/**
|
|
3377
|
+
* DEBUG: Prints current swap query state
|
|
3378
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3379
|
+
*/
|
|
3380
|
+
debugPrintSwapQuery() {
|
|
3381
|
+
super.add(printSwapQuery.createIx(new PrintSwapQueryArgs()));
|
|
3382
|
+
return this;
|
|
3383
|
+
}
|
|
3384
|
+
/**
|
|
3385
|
+
* DEBUG: Prints execution context information
|
|
3386
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3387
|
+
*/
|
|
3388
|
+
debugPrintContext() {
|
|
3389
|
+
super.add(printContext.createIx(new PrintContextArgs()));
|
|
3390
|
+
return this;
|
|
3391
|
+
}
|
|
3392
|
+
/**
|
|
3393
|
+
* DEBUG: Prints calculated amount for swap
|
|
3394
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3395
|
+
*/
|
|
3396
|
+
debugPrintAmountForSwap() {
|
|
3397
|
+
super.add(printAmountForSwap.createIx(new PrintAmountForSwapArgs()));
|
|
3398
|
+
return this;
|
|
3399
|
+
}
|
|
3400
|
+
/**
|
|
3401
|
+
* DEBUG: Prints current free memory pointer value
|
|
3402
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3403
|
+
*/
|
|
3404
|
+
debugPrintFreeMemoryPointer() {
|
|
3405
|
+
super.add(printFreeMemoryPointer.createIx(new PrintFreeMemoryPointerArgs()));
|
|
3406
|
+
return this;
|
|
3407
|
+
}
|
|
3408
|
+
/**
|
|
3409
|
+
* DEBUG: Prints remaining gas
|
|
3410
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3411
|
+
*/
|
|
3412
|
+
debugPrintGasLeft() {
|
|
3413
|
+
super.add(printGasLeft.createIx(new PrintGasLeftArgs()));
|
|
3414
|
+
return this;
|
|
3415
|
+
}
|
|
3416
|
+
};
|
|
3417
|
+
|
|
3418
|
+
//#endregion
|
|
3419
|
+
//#region src/swap-vm/programs/aqua-program-builder.ts
|
|
3420
|
+
var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
|
|
3421
|
+
constructor() {
|
|
3422
|
+
super([...aquaInstructions]);
|
|
3423
|
+
}
|
|
3424
|
+
static decode(program) {
|
|
3425
|
+
return new AquaProgramBuilder().decode(program);
|
|
3426
|
+
}
|
|
3427
|
+
/**
|
|
3428
|
+
* Enables debug mode for the program
|
|
3429
|
+
* WARNING: Debug instructions will throw an error if debug mode is not enabled
|
|
3430
|
+
*/
|
|
3431
|
+
withDebug() {
|
|
3432
|
+
this.ixsSet[0] = printSwapRegisters;
|
|
3433
|
+
this.ixsSet[1] = printSwapQuery;
|
|
3434
|
+
this.ixsSet[2] = printContext;
|
|
3435
|
+
this.ixsSet[3] = printAmountForSwap;
|
|
3436
|
+
this.ixsSet[4] = printFreeMemoryPointer;
|
|
3437
|
+
this.ixsSet[5] = printGasLeft;
|
|
3438
|
+
return this;
|
|
3439
|
+
}
|
|
3440
|
+
/**
|
|
3441
|
+
* Unconditional jump to specified program counter
|
|
3442
|
+
**/
|
|
3443
|
+
jump(data) {
|
|
3444
|
+
super.add(jump.createIx(new JumpArgs(data.nextPC)));
|
|
3445
|
+
return this;
|
|
3446
|
+
}
|
|
3447
|
+
/**
|
|
3448
|
+
* Jumps if tokenIn is the specified token
|
|
3449
|
+
**/
|
|
3450
|
+
jumpIfTokenIn(data) {
|
|
3451
|
+
super.add(jumpIfTokenIn.createIx(new JumpIfTokenArgs(data.tokenTail, data.nextPC)));
|
|
3452
|
+
return this;
|
|
3453
|
+
}
|
|
3454
|
+
/**
|
|
3455
|
+
* Jumps if tokenOut is the specified token
|
|
3456
|
+
**/
|
|
3457
|
+
jumpIfTokenOut(data) {
|
|
3458
|
+
super.add(jumpIfTokenOut.createIx(new JumpIfTokenArgs(data.tokenTail, data.nextPC)));
|
|
3459
|
+
return this;
|
|
3460
|
+
}
|
|
3461
|
+
/**
|
|
3462
|
+
* Reverts if the deadline has been reached
|
|
3463
|
+
**/
|
|
3464
|
+
deadline(data) {
|
|
3465
|
+
super.add(deadline.createIx(new DeadlineArgs(data.deadline)));
|
|
3466
|
+
return this;
|
|
3467
|
+
}
|
|
3468
|
+
/**
|
|
3469
|
+
* Requires taker to hold any amount of specified token (supports NFTs)
|
|
3470
|
+
**/
|
|
3471
|
+
onlyTakerTokenBalanceNonZero(data) {
|
|
3472
|
+
super.add(onlyTakerTokenBalanceNonZero.createIx(new OnlyTakerTokenBalanceNonZeroArgs(data.token)));
|
|
3473
|
+
return this;
|
|
3474
|
+
}
|
|
3475
|
+
/**
|
|
3476
|
+
* Requires taker to hold at least specified amount of token
|
|
3477
|
+
**/
|
|
3478
|
+
onlyTakerTokenBalanceGte(data) {
|
|
3479
|
+
super.add(onlyTakerTokenBalanceGte.createIx(new OnlyTakerTokenBalanceGteArgs(data.token, data.minAmount)));
|
|
3480
|
+
return this;
|
|
3481
|
+
}
|
|
3482
|
+
/**
|
|
3483
|
+
* Requires taker to hold at least specified share of token's total supply
|
|
3484
|
+
**/
|
|
3485
|
+
onlyTakerTokenSupplyShareGte(data) {
|
|
3486
|
+
super.add(onlyTakerTokenSupplyShareGte.createIx(new OnlyTakerTokenSupplyShareGteArgs(data.token, data.minShareE18)));
|
|
3487
|
+
return this;
|
|
3488
|
+
}
|
|
3489
|
+
/**
|
|
3490
|
+
* No-op instruction used to add uniqueness to order hashes (prevents replay attacks)
|
|
3491
|
+
**/
|
|
3492
|
+
salt(data) {
|
|
3493
|
+
super.add(salt.createIx(new SaltArgs(data.salt)));
|
|
3494
|
+
return this;
|
|
3495
|
+
}
|
|
3496
|
+
/**
|
|
3497
|
+
* Basic swap using constant product formula (x*y=k)
|
|
3498
|
+
**/
|
|
3499
|
+
xycSwapXD() {
|
|
3500
|
+
super.add(xycSwapXD.createIx(new XycSwapXDArgs()));
|
|
3501
|
+
return this;
|
|
3502
|
+
}
|
|
3503
|
+
/**
|
|
3504
|
+
* Concentrates liquidity within price bounds for multiple tokens
|
|
3505
|
+
**/
|
|
3506
|
+
concentrateGrowLiquidityXD(data) {
|
|
3507
|
+
super.add(concentrateGrowLiquidityXD.createIx(new ConcentrateGrowLiquidityXDArgs(data.tokenDeltas)));
|
|
3508
|
+
return this;
|
|
3509
|
+
}
|
|
3510
|
+
/**
|
|
3511
|
+
* Concentrates liquidity within price bounds for two tokens
|
|
3512
|
+
**/
|
|
3513
|
+
concentrateGrowLiquidity2D(data) {
|
|
3514
|
+
super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.deltaLt, data.deltaGt)));
|
|
3515
|
+
return this;
|
|
3516
|
+
}
|
|
3517
|
+
/**
|
|
3518
|
+
* Applies time-based decay to balance adjustments
|
|
3519
|
+
**/
|
|
3520
|
+
decayXD(data) {
|
|
3521
|
+
super.add(decayXD.createIx(new DecayXDArgs(data.decayPeriod)));
|
|
3522
|
+
return this;
|
|
3523
|
+
}
|
|
3524
|
+
/**
|
|
3525
|
+
* Applies fee to amountIn
|
|
3526
|
+
**/
|
|
3527
|
+
flatFeeAmountInXD(data) {
|
|
3528
|
+
super.add(flatFeeAmountInXD.createIx(new FlatFeeArgs(data.fee)));
|
|
3529
|
+
return this;
|
|
3530
|
+
}
|
|
3531
|
+
/**
|
|
3532
|
+
* Applies fee to amountOut
|
|
3533
|
+
**/
|
|
3534
|
+
flatFeeAmountOutXD(data) {
|
|
3535
|
+
super.add(flatFeeAmountOutXD.createIx(new FlatFeeArgs(data.fee)));
|
|
3536
|
+
return this;
|
|
3537
|
+
}
|
|
3538
|
+
/**
|
|
3539
|
+
* Applies progressive fee to amountIn
|
|
3540
|
+
**/
|
|
3541
|
+
progressiveFeeInXD(data) {
|
|
3542
|
+
super.add(progressiveFeeInXD.createIx(new FlatFeeArgs(data.fee)));
|
|
3543
|
+
return this;
|
|
3544
|
+
}
|
|
3545
|
+
/**
|
|
3546
|
+
* Applies progressive fee to amountOut
|
|
3547
|
+
**/
|
|
3548
|
+
progressiveFeeOutXD(data) {
|
|
3549
|
+
super.add(progressiveFeeOutXD.createIx(new FlatFeeArgs(data.fee)));
|
|
3550
|
+
return this;
|
|
3551
|
+
}
|
|
3552
|
+
/**
|
|
3553
|
+
* Applies protocol fee to amountOut with direct transfer
|
|
3554
|
+
**/
|
|
3555
|
+
protocolFeeAmountOutXD(data) {
|
|
3556
|
+
super.add(protocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3557
|
+
return this;
|
|
3558
|
+
}
|
|
3559
|
+
/**
|
|
3560
|
+
* Applies protocol fee to amountOut through Aqua protocol
|
|
3561
|
+
**/
|
|
3562
|
+
aquaProtocolFeeAmountOutXD(data) {
|
|
3563
|
+
super.add(aquaProtocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3564
|
+
return this;
|
|
3565
|
+
}
|
|
3566
|
+
/**
|
|
3567
|
+
* DEBUG: Prints current swap registers (amounts and tokens)
|
|
3568
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3569
|
+
*/
|
|
3570
|
+
debugPrintSwapRegisters() {
|
|
3571
|
+
super.add(printSwapRegisters.createIx(new PrintSwapRegistersArgs()));
|
|
3572
|
+
return this;
|
|
3573
|
+
}
|
|
3574
|
+
/**
|
|
3575
|
+
* DEBUG: Prints current swap query state
|
|
3576
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3577
|
+
*/
|
|
3578
|
+
debugPrintSwapQuery() {
|
|
3579
|
+
super.add(printSwapQuery.createIx(new PrintSwapQueryArgs()));
|
|
3580
|
+
return this;
|
|
3581
|
+
}
|
|
3582
|
+
/**
|
|
3583
|
+
* DEBUG: Prints execution context information
|
|
3584
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3585
|
+
*/
|
|
3586
|
+
debugPrintContext() {
|
|
3587
|
+
super.add(printContext.createIx(new PrintContextArgs()));
|
|
3588
|
+
return this;
|
|
3589
|
+
}
|
|
3590
|
+
/**
|
|
3591
|
+
* DEBUG: Prints calculated amount for swap
|
|
3592
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3593
|
+
*/
|
|
3594
|
+
debugPrintAmountForSwap() {
|
|
3595
|
+
super.add(printAmountForSwap.createIx(new PrintAmountForSwapArgs()));
|
|
3596
|
+
return this;
|
|
3597
|
+
}
|
|
3598
|
+
/**
|
|
3599
|
+
* DEBUG: Prints current free memory pointer value
|
|
3600
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3601
|
+
*/
|
|
3602
|
+
debugPrintFreeMemoryPointer() {
|
|
3603
|
+
super.add(printFreeMemoryPointer.createIx(new PrintFreeMemoryPointerArgs()));
|
|
3604
|
+
return this;
|
|
3605
|
+
}
|
|
3606
|
+
/**
|
|
3607
|
+
* DEBUG: Prints remaining gas
|
|
3608
|
+
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3609
|
+
*/
|
|
3610
|
+
debugPrintGasLeft() {
|
|
3611
|
+
super.add(printGasLeft.createIx(new PrintGasLeftArgs()));
|
|
3612
|
+
return this;
|
|
3613
|
+
}
|
|
3614
|
+
};
|
|
3615
|
+
|
|
3616
|
+
//#endregion
|
|
3617
|
+
//#region src/swap-vm/order.ts
|
|
3618
|
+
/**
|
|
3619
|
+
* Representation of a SwapVM order.
|
|
3620
|
+
*/
|
|
3621
|
+
var Order = class Order {
|
|
3622
|
+
static ABI = {
|
|
3623
|
+
type: "tuple",
|
|
3624
|
+
components: [
|
|
3625
|
+
{
|
|
3626
|
+
name: "maker",
|
|
3627
|
+
type: "address"
|
|
3628
|
+
},
|
|
3629
|
+
{
|
|
3630
|
+
name: "traits",
|
|
3631
|
+
type: "uint256"
|
|
3632
|
+
},
|
|
3633
|
+
{
|
|
3634
|
+
name: "data",
|
|
3635
|
+
type: "bytes"
|
|
3636
|
+
}
|
|
3637
|
+
]
|
|
3638
|
+
};
|
|
3639
|
+
constructor(maker, traits, program) {
|
|
3640
|
+
this.maker = maker;
|
|
3641
|
+
this.traits = traits;
|
|
3642
|
+
this.program = program;
|
|
3643
|
+
}
|
|
3644
|
+
static new(params) {
|
|
3645
|
+
return new Order(params.maker, params.traits, params.program);
|
|
3646
|
+
}
|
|
3647
|
+
/**
|
|
3648
|
+
* Reconstructs an `Order` from its ABI-encoded representation.
|
|
3649
|
+
*
|
|
3650
|
+
* 🎯 Non-obvious:
|
|
3651
|
+
* - Any change to how `MakerTraits` packs `hooksData` must preserve the contract that
|
|
3652
|
+
* `hooksDataEndsAtByte(traits)` points exactly to the start of the program, or decoding will drift.
|
|
3653
|
+
*/
|
|
3654
|
+
static decode(encoded) {
|
|
3655
|
+
const [{ maker, traits, data }] = (0, viem.decodeAbiParameters)([Order.ABI], encoded.toString());
|
|
3656
|
+
const makerTraits = MakerTraits.decode(traits, new __1inch_sdk_core.HexString(data));
|
|
3657
|
+
const program = new __1inch_sdk_core.HexString(data).sliceBytes(MakerTraits.hooksDataEndsAtByte(traits));
|
|
3658
|
+
return new Order(new __1inch_sdk_core.Address(maker), makerTraits, new SwapVmProgram(program.toString()));
|
|
3659
|
+
}
|
|
3660
|
+
/**
|
|
3661
|
+
* Computes an order hash used for signing or as a deterministic order identifier.
|
|
3662
|
+
*
|
|
3663
|
+
* Hashing modes:
|
|
3664
|
+
* - Aqua mode (`traits.useAquaInsteadOfSignature === true`):
|
|
3665
|
+
* - Returns `keccak256(encode())`.
|
|
3666
|
+
* - Ignores provided `domain` completely.
|
|
3667
|
+
* - EIP-712 signature mode (`useAquaInsteadOfSignature === false`):
|
|
3668
|
+
* - Requires a `domain`; if missing, an assertion error is thrown.
|
|
3669
|
+
*
|
|
3670
|
+
* ⚠️ IMPORTANT:
|
|
3671
|
+
* - Callers must ensure they pass the same `domain` parameters that the verifier
|
|
3672
|
+
* uses on-chain; mismatches will produce hashes that cannot be verified.
|
|
3673
|
+
*/
|
|
3674
|
+
hash(domain) {
|
|
3675
|
+
if (this.traits.useAquaInsteadOfSignature) return new __1inch_sdk_core.HexString((0, viem.keccak256)(this.encode().toString()));
|
|
3676
|
+
(0, assert.default)(domain, "domain info required if isUseOfAquaInsteadOfSignatureEnabled is false");
|
|
3677
|
+
return new __1inch_sdk_core.HexString((0, viem.hashTypedData)({
|
|
3678
|
+
domain: {
|
|
3679
|
+
...domain,
|
|
3680
|
+
verifyingContract: domain.verifyingContract.toString()
|
|
3681
|
+
},
|
|
3682
|
+
primaryType: "Order",
|
|
3683
|
+
types: { Order: [
|
|
3684
|
+
{
|
|
3685
|
+
name: "maker",
|
|
3686
|
+
type: "address"
|
|
3687
|
+
},
|
|
3688
|
+
{
|
|
3689
|
+
name: "traits",
|
|
3690
|
+
type: "uint256"
|
|
3691
|
+
},
|
|
3692
|
+
{
|
|
3693
|
+
name: "data",
|
|
3694
|
+
type: "bytes"
|
|
3695
|
+
}
|
|
3696
|
+
] },
|
|
3697
|
+
message: this.build()
|
|
3698
|
+
}));
|
|
3699
|
+
}
|
|
3700
|
+
/**
|
|
3701
|
+
* ABI-encodes the order into the exact bytes blob expected by on-chain contracts.
|
|
3702
|
+
*
|
|
3703
|
+
* Usage:
|
|
3704
|
+
* - Input to `keccak256` in Aqua mode (`hash()`).
|
|
3705
|
+
* - Payload for contract methods expecting an `Order` tuple.
|
|
3706
|
+
*/
|
|
3707
|
+
encode() {
|
|
3708
|
+
const encoded = (0, viem.encodeAbiParameters)([Order.ABI], [this.build()]);
|
|
3709
|
+
return new __1inch_sdk_core.HexString(encoded);
|
|
3710
|
+
}
|
|
3711
|
+
/**
|
|
3712
|
+
* Produces the ABI-ready `BuiltOrder` tuple`.
|
|
3713
|
+
*/
|
|
3714
|
+
build() {
|
|
3715
|
+
const { traits, hooksData } = this.traits.encode(this.maker);
|
|
3716
|
+
return {
|
|
3717
|
+
maker: this.maker.toString(),
|
|
3718
|
+
traits,
|
|
3719
|
+
data: hooksData.concat(this.program).toString()
|
|
3720
|
+
};
|
|
3721
|
+
}
|
|
3722
|
+
};
|
|
3723
|
+
|
|
3724
|
+
//#endregion
|
|
3725
|
+
//#region src/swap-vm/strategies/aqua-amm-strategy.ts
|
|
3726
|
+
/**
|
|
3727
|
+
* Aqua AMM Strategy builder that mirrors AquaAMM.sol
|
|
3728
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/strategies/AquaAMM.sol
|
|
3729
|
+
*/
|
|
3730
|
+
var AquaAMMStrategy = class AquaAMMStrategy {
|
|
3731
|
+
feeBpsIn;
|
|
3732
|
+
deltas;
|
|
3733
|
+
decayPeriod;
|
|
3734
|
+
protocolFee;
|
|
3735
|
+
salt;
|
|
3736
|
+
constructor(tokenA, tokenB) {
|
|
3737
|
+
this.tokenA = tokenA;
|
|
3738
|
+
this.tokenB = tokenB;
|
|
3739
|
+
}
|
|
3740
|
+
static new(tokens) {
|
|
3741
|
+
return new AquaAMMStrategy(tokens.tokenA, tokens.tokenB);
|
|
3742
|
+
}
|
|
3743
|
+
withProtocolFee(bps, receiver) {
|
|
3744
|
+
this.protocolFee = {
|
|
3745
|
+
bps,
|
|
3746
|
+
receiver
|
|
3747
|
+
};
|
|
3748
|
+
return this;
|
|
3749
|
+
}
|
|
3750
|
+
withDeltas(a, b) {
|
|
3751
|
+
this.deltas = {
|
|
3752
|
+
a,
|
|
3753
|
+
b
|
|
3754
|
+
};
|
|
3755
|
+
return this;
|
|
3756
|
+
}
|
|
3757
|
+
withDecayPeriod(decayPeriod) {
|
|
3758
|
+
this.decayPeriod = decayPeriod;
|
|
3759
|
+
return this;
|
|
3760
|
+
}
|
|
3761
|
+
withFeeTokenIn(bps) {
|
|
3762
|
+
this.feeBpsIn = bps;
|
|
3763
|
+
return this;
|
|
3764
|
+
}
|
|
3765
|
+
withSalt(salt$1) {
|
|
3766
|
+
this.salt = salt$1;
|
|
3767
|
+
return this;
|
|
3768
|
+
}
|
|
3769
|
+
build() {
|
|
3770
|
+
const builder = new AquaProgramBuilder();
|
|
3771
|
+
if (this.deltas) {
|
|
3772
|
+
const data = ConcentrateGrowLiquidity2DArgs.fromTokenDeltas(this.tokenA, this.tokenB, this.deltas.a, this.deltas.b);
|
|
3773
|
+
builder.add(concentrateGrowLiquidity2D.createIx(data));
|
|
3774
|
+
}
|
|
3775
|
+
if (this.decayPeriod) builder.decayXD({ decayPeriod: this.decayPeriod });
|
|
3776
|
+
if (this.feeBpsIn) {
|
|
3777
|
+
const data = FlatFeeArgs.fromBps(this.feeBpsIn);
|
|
3778
|
+
builder.add(flatFeeAmountInXD.createIx(data));
|
|
3779
|
+
}
|
|
3780
|
+
if (this.protocolFee) {
|
|
3781
|
+
const data = ProtocolFeeArgs.fromBps(this.protocolFee.bps, this.protocolFee.receiver);
|
|
3782
|
+
builder.add(aquaProtocolFeeAmountOutXD.createIx(data));
|
|
3783
|
+
}
|
|
3784
|
+
builder.xycSwapXD();
|
|
3785
|
+
if (this.salt) builder.salt({ salt: this.salt });
|
|
3786
|
+
return builder.build();
|
|
3787
|
+
}
|
|
3788
|
+
};
|
|
3789
|
+
|
|
3790
|
+
//#endregion
|
|
3791
|
+
//#region src/abi/index.ts
|
|
3792
|
+
var abi_exports = {};
|
|
3793
|
+
__export(abi_exports, { SWAP_VM_ABI: () => SWAP_VM_ABI });
|
|
3794
|
+
|
|
3795
|
+
//#endregion
|
|
3796
|
+
Object.defineProperty(exports, 'ABI', {
|
|
3797
|
+
enumerable: true,
|
|
3798
|
+
get: function () {
|
|
3799
|
+
return abi_exports;
|
|
3800
|
+
}
|
|
3801
|
+
});
|
|
3802
|
+
exports.AQUA_SWAP_VM_CONTRACT_ADDRESSES = AQUA_SWAP_VM_CONTRACT_ADDRESSES;
|
|
3803
|
+
Object.defineProperty(exports, 'Address', {
|
|
3804
|
+
enumerable: true,
|
|
3805
|
+
get: function () {
|
|
3806
|
+
return __1inch_sdk_core.Address;
|
|
3807
|
+
}
|
|
3808
|
+
});
|
|
3809
|
+
exports.AquaAMMStrategy = AquaAMMStrategy;
|
|
3810
|
+
exports.AquaProgramBuilder = AquaProgramBuilder;
|
|
3811
|
+
Object.defineProperty(exports, 'CallInfo', {
|
|
3812
|
+
enumerable: true,
|
|
3813
|
+
get: function () {
|
|
3814
|
+
return __1inch_sdk_core.CallInfo;
|
|
3815
|
+
}
|
|
3816
|
+
});
|
|
3817
|
+
Object.defineProperty(exports, 'HexString', {
|
|
3818
|
+
enumerable: true,
|
|
3819
|
+
get: function () {
|
|
3820
|
+
return __1inch_sdk_core.HexString;
|
|
3821
|
+
}
|
|
3822
|
+
});
|
|
3823
|
+
exports.MakerTraits = MakerTraits;
|
|
3824
|
+
Object.defineProperty(exports, 'NetworkEnum', {
|
|
3825
|
+
enumerable: true,
|
|
3826
|
+
get: function () {
|
|
3827
|
+
return __1inch_sdk_core.NetworkEnum;
|
|
3828
|
+
}
|
|
3829
|
+
});
|
|
3830
|
+
exports.Order = Order;
|
|
3831
|
+
exports.ProgramBuilder = ProgramBuilder;
|
|
3832
|
+
exports.RegularProgramBuilder = RegularProgramBuilder;
|
|
3833
|
+
exports.SwapVMContract = SwapVMContract;
|
|
3834
|
+
exports.SwapVmProgram = SwapVmProgram;
|
|
3835
|
+
exports.SwappedEvent = SwappedEvent;
|
|
3836
|
+
exports.TakerTraits = TakerTraits;
|
|
3837
|
+
Object.defineProperty(exports, 'instructions', {
|
|
3838
|
+
enumerable: true,
|
|
3839
|
+
get: function () {
|
|
3840
|
+
return instructions_exports;
|
|
3841
|
+
}
|
|
3842
|
+
});
|