@1inch/swap-vm-sdk 0.1.0 → 0.1.2-rc.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/README.md +26 -25
- package/dist/abi/SwapVM.abi.d.mts +76 -0
- package/dist/abi/SwapVM.abi.d.ts +76 -0
- package/dist/index.js +641 -367
- package/dist/index.mjs +642 -370
- package/dist/swap-vm/instructions/concentrate/bigint-sqrt.d.mts +1 -0
- package/dist/swap-vm/instructions/concentrate/bigint-sqrt.d.ts +1 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.d.mts +16 -7
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.d.ts +16 -7
- package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/types.d.mts +39 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-calculator/types.d.ts +39 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-math/concentrate-liquidity-math.d.mts +51 -0
- package/dist/swap-vm/instructions/concentrate/concentrate-liquidity-math/concentrate-liquidity-math.d.ts +51 -0
- package/dist/swap-vm/instructions/concentrate/index.d.mts +4 -4
- package/dist/swap-vm/instructions/concentrate/index.d.ts +4 -4
- package/dist/swap-vm/instructions/concentrate/opcodes.d.mts +0 -5
- package/dist/swap-vm/instructions/concentrate/opcodes.d.ts +0 -5
- package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args.d.mts +1 -2
- package/dist/swap-vm/instructions/dutch-auction/dutch-auction-args.d.ts +1 -2
- package/dist/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args.d.mts +13 -0
- package/dist/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args.d.ts +13 -0
- package/dist/swap-vm/instructions/fee/{flat-fee-args-coder.d.mts → flat-fee/flat-fee-args-coder.d.mts} +1 -1
- package/dist/swap-vm/instructions/fee/{flat-fee-args-coder.d.ts → flat-fee/flat-fee-args-coder.d.ts} +1 -1
- package/dist/swap-vm/instructions/fee/{flat-fee-args.d.mts → flat-fee/flat-fee-args.d.mts} +2 -2
- package/dist/swap-vm/instructions/fee/{flat-fee-args.d.ts → flat-fee/flat-fee-args.d.ts} +2 -2
- package/dist/swap-vm/instructions/fee/index.d.mts +3 -2
- package/dist/swap-vm/instructions/fee/index.d.ts +3 -2
- package/dist/swap-vm/instructions/fee/opcodes.d.mts +28 -8
- package/dist/swap-vm/instructions/fee/opcodes.d.ts +28 -8
- package/dist/swap-vm/instructions/fee/{protocol-fee-args-coder.d.mts → protocol-fee/protocol-fee-args-coder.d.mts} +1 -1
- package/dist/swap-vm/instructions/fee/{protocol-fee-args-coder.d.ts → protocol-fee/protocol-fee-args-coder.d.ts} +1 -1
- package/dist/swap-vm/instructions/fee/{protocol-fee-args.d.mts → protocol-fee/protocol-fee-args.d.mts} +3 -3
- package/dist/swap-vm/instructions/fee/{protocol-fee-args.d.ts → protocol-fee/protocol-fee-args.d.ts} +3 -3
- package/dist/swap-vm/instructions/index.d.mts +2 -1
- package/dist/swap-vm/instructions/index.d.ts +2 -1
- package/dist/swap-vm/instructions/pegged-swap/index.d.mts +3 -0
- package/dist/swap-vm/instructions/pegged-swap/index.d.ts +3 -0
- package/dist/swap-vm/instructions/pegged-swap/opcodes.d.mts +5 -0
- package/dist/swap-vm/instructions/pegged-swap/opcodes.d.ts +5 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-args-coder.d.mts +7 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-args-coder.d.ts +7 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-args.d.mts +29 -0
- package/dist/swap-vm/instructions/pegged-swap/pegged-swap-args.d.ts +29 -0
- package/dist/swap-vm/instructions/pegged-swap/rate-resolver.d.mts +1 -0
- package/dist/swap-vm/instructions/pegged-swap/rate-resolver.d.ts +1 -0
- package/dist/swap-vm/instructions/pegged-swap/types.d.mts +6 -0
- package/dist/swap-vm/instructions/pegged-swap/types.d.ts +6 -0
- package/dist/swap-vm/programs/aqua-program-builder.d.mts +13 -16
- package/dist/swap-vm/programs/aqua-program-builder.d.ts +13 -16
- package/dist/swap-vm/programs/regular-program-builder.d.mts +21 -9
- package/dist/swap-vm/programs/regular-program-builder.d.ts +21 -9
- package/dist/swap-vm/strategies/aqua-amm-strategy.d.mts +2 -19
- package/dist/swap-vm/strategies/aqua-amm-strategy.d.ts +2 -19
- package/dist/swap-vm/strategies/aqua-pegged-amm-strategy.d.mts +11 -0
- package/dist/swap-vm/strategies/aqua-pegged-amm-strategy.d.ts +11 -0
- package/dist/swap-vm/strategies/aqua-xyc-amm-strategy.d.mts +11 -0
- package/dist/swap-vm/strategies/aqua-xyc-amm-strategy.d.ts +11 -0
- package/dist/swap-vm/strategies/index.d.mts +3 -0
- package/dist/swap-vm/strategies/index.d.ts +3 -0
- package/dist/swap-vm/strategies/types.d.mts +19 -0
- package/dist/swap-vm/strategies/types.d.ts +19 -0
- package/dist/swap-vm/taker-traits.d.mts +12 -2
- package/dist/swap-vm/taker-traits.d.ts +12 -2
- package/package.json +18 -18
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.d.mts +0 -7
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.d.ts +0 -7
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.d.mts +0 -17
- package/dist/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.d.ts +0 -17
- package/dist/swap-vm/instructions/concentrate/types.d.mts +0 -5
- package/dist/swap-vm/instructions/concentrate/types.d.ts +0 -5
- package/dist/swap-vm/instructions/concentrate/utils.d.mts +0 -4
- package/dist/swap-vm/instructions/concentrate/utils.d.ts +0 -4
- package/dist/swap-vm/instructions/stable-swap/index.d.mts +0 -2
- package/dist/swap-vm/instructions/stable-swap/index.d.ts +0 -2
- package/dist/swap-vm/instructions/stable-swap/opcodes.d.mts +0 -4
- package/dist/swap-vm/instructions/stable-swap/opcodes.d.ts +0 -4
- package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.d.mts +0 -7
- package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args-coder.d.ts +0 -7
- package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args.d.mts +0 -25
- package/dist/swap-vm/instructions/stable-swap/stable-swap-2d-args.d.ts +0 -25
- package/dist/swap-vm/types.d.mts +0 -22
- package/dist/swap-vm/types.d.ts +0 -22
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ const viem = __toESM(require("viem"));
|
|
|
31
31
|
const __1inch_sdk_core = __toESM(require("@1inch/sdk-core"));
|
|
32
32
|
const __1inch_byte_utils = __toESM(require("@1inch/byte-utils"));
|
|
33
33
|
const assert = __toESM(require("assert"));
|
|
34
|
-
const
|
|
34
|
+
const __1inch_byte_utils_dist_constants = __toESM(require("@1inch/byte-utils/dist/constants"));
|
|
35
35
|
|
|
36
36
|
//#region src/abi/SwapVM.abi.ts
|
|
37
37
|
const SWAP_VM_ABI = [
|
|
@@ -348,6 +348,11 @@ const SWAP_VM_ABI = [
|
|
|
348
348
|
name: "amount",
|
|
349
349
|
type: "uint256",
|
|
350
350
|
internalType: "uint256"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "amountNetPulled",
|
|
354
|
+
type: "uint256",
|
|
355
|
+
internalType: "uint256"
|
|
351
356
|
}
|
|
352
357
|
]
|
|
353
358
|
},
|
|
@@ -415,6 +420,89 @@ const SWAP_VM_ABI = [
|
|
|
415
420
|
internalType: "uint256"
|
|
416
421
|
}]
|
|
417
422
|
},
|
|
423
|
+
{
|
|
424
|
+
type: "error",
|
|
425
|
+
name: "DeadlineReached",
|
|
426
|
+
inputs: [{
|
|
427
|
+
name: "taker",
|
|
428
|
+
type: "address",
|
|
429
|
+
internalType: "address"
|
|
430
|
+
}, {
|
|
431
|
+
name: "deadline",
|
|
432
|
+
type: "uint256",
|
|
433
|
+
internalType: "uint256"
|
|
434
|
+
}]
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
type: "error",
|
|
438
|
+
name: "TakerTokenBalanceIsZero",
|
|
439
|
+
inputs: [{
|
|
440
|
+
name: "taker",
|
|
441
|
+
type: "address",
|
|
442
|
+
internalType: "address"
|
|
443
|
+
}, {
|
|
444
|
+
name: "token",
|
|
445
|
+
type: "address",
|
|
446
|
+
internalType: "address"
|
|
447
|
+
}]
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
type: "error",
|
|
451
|
+
name: "TakerTokenBalanceIsLessThanRequired",
|
|
452
|
+
inputs: [
|
|
453
|
+
{
|
|
454
|
+
name: "taker",
|
|
455
|
+
type: "address",
|
|
456
|
+
internalType: "address"
|
|
457
|
+
},
|
|
458
|
+
{
|
|
459
|
+
name: "token",
|
|
460
|
+
type: "address",
|
|
461
|
+
internalType: "address"
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
name: "balance",
|
|
465
|
+
type: "uint256",
|
|
466
|
+
internalType: "uint256"
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
name: "minAmount",
|
|
470
|
+
type: "uint256",
|
|
471
|
+
internalType: "uint256"
|
|
472
|
+
}
|
|
473
|
+
]
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
type: "error",
|
|
477
|
+
name: "TakerTokenBalanceSupplyShareIsLessThanRequired",
|
|
478
|
+
inputs: [
|
|
479
|
+
{
|
|
480
|
+
name: "taker",
|
|
481
|
+
type: "address",
|
|
482
|
+
internalType: "address"
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
name: "token",
|
|
486
|
+
type: "address",
|
|
487
|
+
internalType: "address"
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
name: "balance",
|
|
491
|
+
type: "uint256",
|
|
492
|
+
internalType: "uint256"
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
name: "totalSupply",
|
|
496
|
+
type: "uint256",
|
|
497
|
+
internalType: "uint256"
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
name: "minShareE18",
|
|
501
|
+
type: "uint256",
|
|
502
|
+
internalType: "uint256"
|
|
503
|
+
}
|
|
504
|
+
]
|
|
505
|
+
},
|
|
418
506
|
{
|
|
419
507
|
type: "error",
|
|
420
508
|
name: "SafeTransferFromFailed",
|
|
@@ -516,6 +604,11 @@ const SWAP_VM_ABI = [
|
|
|
516
604
|
internalType: "uint256"
|
|
517
605
|
}]
|
|
518
606
|
},
|
|
607
|
+
{
|
|
608
|
+
type: "error",
|
|
609
|
+
name: "TakerTraitsDeadlineExpired",
|
|
610
|
+
inputs: []
|
|
611
|
+
},
|
|
519
612
|
{
|
|
520
613
|
type: "error",
|
|
521
614
|
name: "UnexpectedLock",
|
|
@@ -861,7 +954,7 @@ var MakerTraits = class MakerTraits {
|
|
|
861
954
|
traits = traits.setMask(MakerTraits.CUSTOM_RECEIVER_MASK, BigInt(this.customReceiver?.toString() || 0n));
|
|
862
955
|
const { data, offsets } = MakerTraits.HOOKS.reduce((acc, hookName, i) => {
|
|
863
956
|
const hook = this[hookName];
|
|
864
|
-
const hasTarget = this.hasTargetForHook(hookName);
|
|
957
|
+
const hasTarget = this.hasTargetForHook(hookName, maker);
|
|
865
958
|
const encoded = hook && hasTarget ? hook.encode() : hook?.data || __1inch_sdk_core.HexString.EMPTY;
|
|
866
959
|
acc.sum += BigInt(encoded.bytesCount());
|
|
867
960
|
acc.offsets += acc.sum << 16n * BigInt(i);
|
|
@@ -908,7 +1001,7 @@ var TakerTraits = class TakerTraits {
|
|
|
908
1001
|
static IS_STRICT_THRESHOLD_BIT_FLAG = 4n;
|
|
909
1002
|
static IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG = 5n;
|
|
910
1003
|
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) {
|
|
1004
|
+
constructor(exactIn, shouldUnwrap, preTransferInCallbackEnabled, preTransferOutCallbackEnabled, strictThreshold, firstTransferFromTaker, useTransferFromAndAquaPush, threshold = 0n, customReceiver = __1inch_sdk_core.Address.ZERO_ADDRESS, deadline$1 = 0n, 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
1005
|
this.exactIn = exactIn;
|
|
913
1006
|
this.shouldUnwrap = shouldUnwrap;
|
|
914
1007
|
this.preTransferInCallbackEnabled = preTransferInCallbackEnabled;
|
|
@@ -918,6 +1011,7 @@ var TakerTraits = class TakerTraits {
|
|
|
918
1011
|
this.useTransferFromAndAquaPush = useTransferFromAndAquaPush;
|
|
919
1012
|
this.threshold = threshold;
|
|
920
1013
|
this.customReceiver = customReceiver;
|
|
1014
|
+
this.deadline = deadline$1;
|
|
921
1015
|
this.preTransferInHookData = preTransferInHookData;
|
|
922
1016
|
this.postTransferInHookData = postTransferInHookData;
|
|
923
1017
|
this.preTransferOutHookData = preTransferOutHookData;
|
|
@@ -932,7 +1026,7 @@ var TakerTraits = class TakerTraits {
|
|
|
932
1026
|
* Provides default values for unspecified fields.
|
|
933
1027
|
*/
|
|
934
1028
|
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);
|
|
1029
|
+
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.deadline, data.preTransferInHookData, data.postTransferInHookData, data.preTransferOutHookData, data.postTransferOutHookData, data.preTransferInCallbackData, data.preTransferOutCallbackData, data.instructionsArgs, data.signature);
|
|
936
1030
|
}
|
|
937
1031
|
/**
|
|
938
1032
|
* Creates a default TakerTraits instance with standard settings.
|
|
@@ -952,6 +1046,7 @@ var TakerTraits = class TakerTraits {
|
|
|
952
1046
|
firstTransferFromTaker: false,
|
|
953
1047
|
useTransferFromAndAquaPush: true,
|
|
954
1048
|
threshold: 0n,
|
|
1049
|
+
deadline: 0n,
|
|
955
1050
|
customReceiver: __1inch_sdk_core.Address.ZERO_ADDRESS,
|
|
956
1051
|
preTransferInHookData: __1inch_sdk_core.HexString.EMPTY,
|
|
957
1052
|
postTransferInHookData: __1inch_sdk_core.HexString.EMPTY,
|
|
@@ -966,16 +1061,16 @@ var TakerTraits = class TakerTraits {
|
|
|
966
1061
|
/**
|
|
967
1062
|
* Decodes a packed TakerTraits from a hex string.
|
|
968
1063
|
* The packed format consists of:
|
|
969
|
-
* -
|
|
1064
|
+
* - 20 bytes: 10 uint16 offsets for data sections
|
|
970
1065
|
* - 2 bytes: uint16 flags
|
|
971
|
-
* - Variable: data sections (threshold, to, hook data, callback data, etc.)
|
|
1066
|
+
* - Variable: data sections (threshold, to, deadline, hook data, callback data, etc.)
|
|
972
1067
|
* - Variable: signature
|
|
973
1068
|
*/
|
|
974
1069
|
static decode(packed) {
|
|
975
1070
|
const iter = __1inch_byte_utils.BytesIter.BigInt(packed.toString());
|
|
976
|
-
const offsets = Array.from({ length:
|
|
1071
|
+
const offsets = Array.from({ length: 10 }, () => Number(iter.nextUint16())).reverse();
|
|
977
1072
|
const flags = new __1inch_byte_utils.BN(iter.nextUint16());
|
|
978
|
-
const dataStr = (0, __1inch_byte_utils.trim0x)(packed.toString()).slice(
|
|
1073
|
+
const dataStr = (0, __1inch_byte_utils.trim0x)(packed.toString()).slice(44);
|
|
979
1074
|
const sections = [];
|
|
980
1075
|
offsets.forEach((offset, i) => {
|
|
981
1076
|
const start = i === 0 ? 0 : offsets[i - 1];
|
|
@@ -983,7 +1078,7 @@ var TakerTraits = class TakerTraits {
|
|
|
983
1078
|
});
|
|
984
1079
|
const lastOffset = offsets[offsets.length - 1];
|
|
985
1080
|
const signature = dataStr.length > lastOffset * 2 ? dataStr.slice(lastOffset * 2) : "";
|
|
986
|
-
const [threshold, to, preTransferInHookData, postTransferInHookData, preTransferOutHookData, postTransferOutHookData, preTransferInCallbackData, preTransferOutCallbackData, instructionsArgs] = sections;
|
|
1081
|
+
const [threshold, to, deadline$1, preTransferInHookData, postTransferInHookData, preTransferOutHookData, postTransferOutHookData, preTransferInCallbackData, preTransferOutCallbackData, instructionsArgs] = sections;
|
|
987
1082
|
return TakerTraits.new({
|
|
988
1083
|
exactIn: Boolean(flags.getBit(TakerTraits.IS_EXACT_IN_BIT_FLAG)),
|
|
989
1084
|
shouldUnwrap: Boolean(flags.getBit(TakerTraits.SHOULD_UNWRAP_BIT_FLAG)),
|
|
@@ -994,6 +1089,7 @@ var TakerTraits = class TakerTraits {
|
|
|
994
1089
|
useTransferFromAndAquaPush: Boolean(flags.getBit(TakerTraits.USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG)),
|
|
995
1090
|
threshold: threshold ? BigInt((0, __1inch_byte_utils.add0x)(threshold)) : 0n,
|
|
996
1091
|
customReceiver: to ? new __1inch_sdk_core.Address((0, __1inch_byte_utils.add0x)(to)) : __1inch_sdk_core.Address.ZERO_ADDRESS,
|
|
1092
|
+
deadline: deadline$1 ? BigInt((0, __1inch_byte_utils.add0x)(deadline$1)) : 0n,
|
|
997
1093
|
preTransferInHookData: preTransferInHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(preTransferInHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
998
1094
|
postTransferInHookData: postTransferInHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(postTransferInHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
999
1095
|
preTransferOutHookData: preTransferOutHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(preTransferOutHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
@@ -1022,6 +1118,7 @@ var TakerTraits = class TakerTraits {
|
|
|
1022
1118
|
const dataFields = [
|
|
1023
1119
|
this.threshold > 0n ? new __1inch_sdk_core.HexString("0x" + this.threshold.toString(16).padStart(64, "0")) : __1inch_sdk_core.HexString.EMPTY,
|
|
1024
1120
|
!this.customReceiver.isZero() ? new __1inch_sdk_core.HexString(this.customReceiver.toString()) : __1inch_sdk_core.HexString.EMPTY,
|
|
1121
|
+
this.deadline > 0n ? new __1inch_sdk_core.HexString("0x" + this.deadline.toString(16).padStart(10, "0")) : __1inch_sdk_core.HexString.EMPTY,
|
|
1025
1122
|
this.preTransferInHookData,
|
|
1026
1123
|
this.postTransferInHookData,
|
|
1027
1124
|
this.preTransferOutHookData,
|
|
@@ -1291,7 +1388,7 @@ var JumpArgs = class JumpArgs {
|
|
|
1291
1388
|
static CODER = new JumpArgsCoder();
|
|
1292
1389
|
constructor(nextPC) {
|
|
1293
1390
|
this.nextPC = nextPC;
|
|
1294
|
-
(0,
|
|
1391
|
+
(0, assert.default)(nextPC <= UINT_16_MAX$3 && nextPC >= 0n, `Invalid nextPC value: ${nextPC}. Must be between 0 and 65535`);
|
|
1295
1392
|
}
|
|
1296
1393
|
/**
|
|
1297
1394
|
* Decodes hex data into JumpArgs instance
|
|
@@ -1436,7 +1533,7 @@ var OnlyTakerTokenBalanceGteArgs = class OnlyTakerTokenBalanceGteArgs {
|
|
|
1436
1533
|
constructor(token, minAmount) {
|
|
1437
1534
|
this.token = token;
|
|
1438
1535
|
this.minAmount = minAmount;
|
|
1439
|
-
(0,
|
|
1536
|
+
(0, assert.default)(minAmount >= 0n, "minAmount must be non-negative");
|
|
1440
1537
|
}
|
|
1441
1538
|
/**
|
|
1442
1539
|
* Decodes hex data into OnlyTakerTokenBalanceGteArgs instance
|
|
@@ -1472,7 +1569,7 @@ var OnlyTakerTokenSupplyShareGteArgsCoder = class {
|
|
|
1472
1569
|
|
|
1473
1570
|
//#endregion
|
|
1474
1571
|
//#region src/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.ts
|
|
1475
|
-
const UINT_64_MAX$
|
|
1572
|
+
const UINT_64_MAX$5 = 0xffffffffffffffffn;
|
|
1476
1573
|
/**
|
|
1477
1574
|
* Arguments for checking if taker holds at least specified share of token's total supply
|
|
1478
1575
|
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
|
|
@@ -1482,7 +1579,7 @@ var OnlyTakerTokenSupplyShareGteArgs = class OnlyTakerTokenSupplyShareGteArgs {
|
|
|
1482
1579
|
constructor(token, minShareE18) {
|
|
1483
1580
|
this.token = token;
|
|
1484
1581
|
this.minShareE18 = minShareE18;
|
|
1485
|
-
(0,
|
|
1582
|
+
(0, assert.default)(minShareE18 >= 0n && minShareE18 <= UINT_64_MAX$5, `Invalid minShareE18 value: ${minShareE18}. Must be a valid uint64`);
|
|
1486
1583
|
}
|
|
1487
1584
|
/**
|
|
1488
1585
|
* Decodes hex data into OnlyTakerTokenSupplyShareGteArgs instance
|
|
@@ -1523,7 +1620,7 @@ var SaltArgs = class SaltArgs {
|
|
|
1523
1620
|
static CODER = new SaltArgsCoder();
|
|
1524
1621
|
constructor(salt$1) {
|
|
1525
1622
|
this.salt = salt$1;
|
|
1526
|
-
(0,
|
|
1623
|
+
(0, assert.default)(salt$1 >= 0n && salt$1 <= __1inch_byte_utils.UINT_64_MAX, `Invalid salt value: ${salt$1}. Must be a valid uint64`);
|
|
1527
1624
|
}
|
|
1528
1625
|
/**
|
|
1529
1626
|
* Decodes hex data into SaltArgs instance
|
|
@@ -1613,7 +1710,7 @@ var InvalidateBit1DArgs = class InvalidateBit1DArgs {
|
|
|
1613
1710
|
static CODER = new InvalidateBit1DArgsCoder();
|
|
1614
1711
|
constructor(bitIndex) {
|
|
1615
1712
|
this.bitIndex = bitIndex;
|
|
1616
|
-
(0,
|
|
1713
|
+
(0, assert.default)(bitIndex >= 0n && bitIndex <= __1inch_byte_utils.UINT_32_MAX, `Invalid bitIndex value: ${bitIndex}. Must be a valid uint32`);
|
|
1617
1714
|
}
|
|
1618
1715
|
/**
|
|
1619
1716
|
* Decodes hex data into InvalidateBit1DArgs instance
|
|
@@ -1751,100 +1848,71 @@ __export(xyc_swap_exports, {
|
|
|
1751
1848
|
xycSwapXD: () => xycSwapXD
|
|
1752
1849
|
});
|
|
1753
1850
|
|
|
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
1851
|
//#endregion
|
|
1810
1852
|
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.ts
|
|
1811
1853
|
var ConcentrateGrowLiquidity2DArgsCoder = class {
|
|
1812
1854
|
encode(args) {
|
|
1813
1855
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1814
|
-
builder.addUint256(args.
|
|
1815
|
-
builder.addUint256(args.
|
|
1856
|
+
builder.addUint256(args.sqrtPriceMin);
|
|
1857
|
+
builder.addUint256(args.sqrtPriceMax);
|
|
1816
1858
|
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
1817
1859
|
}
|
|
1818
1860
|
decode(data) {
|
|
1819
1861
|
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
1820
|
-
const
|
|
1821
|
-
const
|
|
1822
|
-
return new ConcentrateGrowLiquidity2DArgs(
|
|
1862
|
+
const sqrtPriceMin = iter.nextUint256();
|
|
1863
|
+
const sqrtPriceMax = iter.nextUint256();
|
|
1864
|
+
return new ConcentrateGrowLiquidity2DArgs(sqrtPriceMin, sqrtPriceMax);
|
|
1823
1865
|
}
|
|
1824
1866
|
};
|
|
1825
1867
|
|
|
1868
|
+
//#endregion
|
|
1869
|
+
//#region src/swap-vm/instructions/concentrate/bigint-sqrt.ts
|
|
1870
|
+
function bigintSqrt(value) {
|
|
1871
|
+
if (value < 0n) throw new Error("square root of negative numbers is not supported");
|
|
1872
|
+
if (value < 2n) return value;
|
|
1873
|
+
if (value <= 9007199254740991n) return BigInt(Math.floor(Math.sqrt(Number(value))));
|
|
1874
|
+
let x0 = value;
|
|
1875
|
+
let x1 = value / x0 + x0 >> 1n;
|
|
1876
|
+
while (x1 < x0) {
|
|
1877
|
+
x0 = x1;
|
|
1878
|
+
x1 = value / x0 + x0 >> 1n;
|
|
1879
|
+
}
|
|
1880
|
+
return x0;
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1826
1883
|
//#endregion
|
|
1827
1884
|
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.ts
|
|
1885
|
+
const ONE_E18 = 10n ** 18n;
|
|
1828
1886
|
/**
|
|
1829
|
-
* Arguments for concentrateGrowLiquidity2D instruction
|
|
1887
|
+
* Arguments for concentrateGrowLiquidity2D instruction
|
|
1888
|
+
* Contract encodes sqrtPriceMin and sqrtPriceMax (2 × uint256, 64 bytes)
|
|
1889
|
+
* P = tokenGt/tokenLt; sqrt(P) in 1e18 fixed-point
|
|
1830
1890
|
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
|
|
1831
1891
|
**/
|
|
1832
1892
|
var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
|
|
1833
1893
|
static CODER = new ConcentrateGrowLiquidity2DArgsCoder();
|
|
1834
|
-
constructor(
|
|
1835
|
-
this.
|
|
1836
|
-
this.
|
|
1837
|
-
(0,
|
|
1838
|
-
(0,
|
|
1894
|
+
constructor(sqrtPriceMin, sqrtPriceMax) {
|
|
1895
|
+
this.sqrtPriceMin = sqrtPriceMin;
|
|
1896
|
+
this.sqrtPriceMax = sqrtPriceMax;
|
|
1897
|
+
(0, assert.default)(sqrtPriceMin > 0n && sqrtPriceMin <= __1inch_byte_utils.UINT_256_MAX, `Invalid sqrtPriceMin: ${sqrtPriceMin}. Must be > 0 and <= UINT_256_MAX`);
|
|
1898
|
+
(0, assert.default)(sqrtPriceMax > 0n && sqrtPriceMax <= __1inch_byte_utils.UINT_256_MAX, `Invalid sqrtPriceMax: ${sqrtPriceMax}. Must be > 0 and <= UINT_256_MAX`);
|
|
1899
|
+
(0, assert.default)(sqrtPriceMin < sqrtPriceMax, `Invalid bounds: sqrtPriceMin (${sqrtPriceMin}) must be < sqrtPriceMax (${sqrtPriceMax})`);
|
|
1900
|
+
}
|
|
1901
|
+
/**
|
|
1902
|
+
* Build args from sqrt prices (1e18 fixed-point).
|
|
1903
|
+
* sqrtPriceMin/Max = sqrt(P) where P = tokenGt/tokenLt.
|
|
1904
|
+
**/
|
|
1905
|
+
static fromSqrtPrices(sqrtPriceMin, sqrtPriceMax) {
|
|
1906
|
+
return new ConcentrateGrowLiquidity2DArgs(sqrtPriceMin, sqrtPriceMax);
|
|
1839
1907
|
}
|
|
1840
1908
|
/**
|
|
1841
|
-
*
|
|
1909
|
+
* Build args from raw prices P_min, P_max (1e18 fixed-point).
|
|
1910
|
+
* Computes sqrtPrice = sqrt(P * 1e18) so that (sqrtPrice/1e18)^2 = P/1e18.
|
|
1842
1911
|
**/
|
|
1843
|
-
static
|
|
1844
|
-
const
|
|
1845
|
-
const
|
|
1846
|
-
|
|
1847
|
-
return new ConcentrateGrowLiquidity2DArgs(deltaLt, deltaGt);
|
|
1912
|
+
static fromRawPrices(rawPriceMin, rawPriceMax) {
|
|
1913
|
+
const sqrtPriceMin = bigintSqrt(rawPriceMin * ONE_E18);
|
|
1914
|
+
const sqrtPriceMax = bigintSqrt(rawPriceMax * ONE_E18);
|
|
1915
|
+
return new ConcentrateGrowLiquidity2DArgs(sqrtPriceMin, sqrtPriceMax);
|
|
1848
1916
|
}
|
|
1849
1917
|
/**
|
|
1850
1918
|
* Decodes hex data into ConcentrateGrowLiquidity2DArgs instance
|
|
@@ -1854,8 +1922,8 @@ var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
|
|
|
1854
1922
|
}
|
|
1855
1923
|
toJSON() {
|
|
1856
1924
|
return {
|
|
1857
|
-
|
|
1858
|
-
|
|
1925
|
+
sqrtPriceMin: this.sqrtPriceMin.toString(),
|
|
1926
|
+
sqrtPriceMax: this.sqrtPriceMax.toString()
|
|
1859
1927
|
};
|
|
1860
1928
|
}
|
|
1861
1929
|
};
|
|
@@ -1863,36 +1931,97 @@ var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
|
|
|
1863
1931
|
//#endregion
|
|
1864
1932
|
//#region src/swap-vm/instructions/concentrate/opcodes.ts
|
|
1865
1933
|
/**
|
|
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
1934
|
* Concentrates liquidity within price bounds for two tokens
|
|
1872
1935
|
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
|
|
1873
1936
|
**/
|
|
1874
1937
|
const concentrateGrowLiquidity2D = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidity2D"), ConcentrateGrowLiquidity2DArgs.CODER);
|
|
1875
1938
|
|
|
1876
1939
|
//#endregion
|
|
1877
|
-
//#region src/swap-vm/instructions/concentrate/
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1940
|
+
//#region src/swap-vm/instructions/concentrate/concentrate-liquidity-math/concentrate-liquidity-math.ts
|
|
1941
|
+
const ONE = 10n ** 18n;
|
|
1942
|
+
/**
|
|
1943
|
+
* Compute max achievable L from available token amounts at a given spot price.
|
|
1944
|
+
* Takes the minimum of L implied by each token, then returns the resulting
|
|
1945
|
+
* targetL and the actual amounts (actualLt, actualGt) needed.
|
|
1946
|
+
*
|
|
1947
|
+
* Mirrors XYCConcentrateArgsBuilder.computeLiquidityFromAmounts in XYCConcentrate.sol.
|
|
1948
|
+
*
|
|
1949
|
+
* @param availableLt Available amount of token with lower address
|
|
1950
|
+
* @param availableGt Available amount of token with higher address
|
|
1951
|
+
* @param sqrtPspot sqrt(P_spot) in 1e18 fixed-point
|
|
1952
|
+
* @param sqrtPmin sqrt(P_min) in 1e18 fixed-point
|
|
1953
|
+
* @param sqrtPmax sqrt(P_max) in 1e18 fixed-point
|
|
1954
|
+
* @returns { targetL, actualLt, actualGt } max L and amounts actually needed (<= available)
|
|
1955
|
+
*/
|
|
1956
|
+
function computeLiquidityFromAmounts(availableLt, availableGt, sqrtPspot, sqrtPmin, sqrtPmax) {
|
|
1957
|
+
if (sqrtPmin >= sqrtPmax) throw new Error("sqrtPmax should be greater than sqrtPmin");
|
|
1958
|
+
const lFromLt = sqrtPmax > sqrtPspot ? mulDiv(availableLt, mulDiv(sqrtPmax, sqrtPspot, ONE), sqrtPmax - sqrtPspot) : __1inch_byte_utils.UINT_256_MAX;
|
|
1959
|
+
const lFromGt = sqrtPspot > sqrtPmin ? mulDiv(availableGt, ONE, sqrtPspot - sqrtPmin) : __1inch_byte_utils.UINT_256_MAX;
|
|
1960
|
+
const targetL = lFromLt < lFromGt ? lFromLt : lFromGt;
|
|
1961
|
+
const { bLt: actualLt, bGt: actualGt } = computeBalances(targetL, sqrtPspot, sqrtPmin, sqrtPmax);
|
|
1882
1962
|
return {
|
|
1883
|
-
|
|
1884
|
-
|
|
1963
|
+
targetL,
|
|
1964
|
+
actualLt,
|
|
1965
|
+
actualGt
|
|
1885
1966
|
};
|
|
1886
1967
|
}
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1968
|
+
/**
|
|
1969
|
+
* Compute the initial balances for given L, P_spot, P_min, P_max:
|
|
1970
|
+
* bLt = L * (sqrtPmax - sqrtPspot) / (sqrtPmax * sqrtPspot / ONE)
|
|
1971
|
+
* bGt = L * (sqrtPspot - sqrtPmin)
|
|
1972
|
+
*
|
|
1973
|
+
* Mirrors XYCConcentrateArgsBuilder.computeBalances in XYCConcentrate.sol.
|
|
1974
|
+
*
|
|
1975
|
+
* @param targetL Liquidity L (1e18 scale implied by ONE)
|
|
1976
|
+
* @param sqrtPspot sqrt(P_spot) in 1e18 fixed-point
|
|
1977
|
+
* @param sqrtPmin sqrt(P_min) in 1e18 fixed-point
|
|
1978
|
+
* @param sqrtPmax sqrt(P_max) in 1e18 fixed-point
|
|
1979
|
+
* @returns { bLt, bGt } amounts of tokenLt and tokenGt for the given L and prices
|
|
1980
|
+
*/
|
|
1981
|
+
function computeBalances(targetL, sqrtPspot, sqrtPmin, sqrtPmax) {
|
|
1982
|
+
if (sqrtPmin >= sqrtPmax) throw new Error("sqrtPmax should be greater than sqrtPmin");
|
|
1983
|
+
const bLt = sqrtPmax > sqrtPspot ? mulDiv(targetL, sqrtPmax - sqrtPspot, mulDiv(sqrtPmax, sqrtPspot, ONE)) : 0n;
|
|
1984
|
+
const bGt = sqrtPspot > sqrtPmin ? mulDiv(targetL, sqrtPspot - sqrtPmin, ONE) : 0n;
|
|
1985
|
+
return {
|
|
1986
|
+
bLt,
|
|
1987
|
+
bGt
|
|
1988
|
+
};
|
|
1989
|
+
}
|
|
1990
|
+
/**
|
|
1991
|
+
* Compute the implied spot price and liquidity from real balances and price bounds.
|
|
1992
|
+
*
|
|
1993
|
+
* Mirrors XYCConcentrateArgsBuilder.computeLiquidityAndPrice in XYCConcentrate.sol.
|
|
1994
|
+
*
|
|
1995
|
+
* @param balanceLt Real balance of the token with lower address
|
|
1996
|
+
* @param balanceGt Real balance of the token with higher address
|
|
1997
|
+
* @param sqrtPriceMin sqrt(P_min) in 1e18 fixed-point
|
|
1998
|
+
* @param sqrtPriceMax sqrt(P_max) in 1e18 fixed-point
|
|
1999
|
+
* @returns { liquidity, sqrtPriceSpot } L and implied sqrt(P_spot) in 1e18 fixed-point
|
|
2000
|
+
*/
|
|
2001
|
+
function computeLiquidityAndPrice(balanceLt, balanceGt, sqrtPriceMin, sqrtPriceMax) {
|
|
2002
|
+
const liquidity = computeL(balanceLt, balanceGt, sqrtPriceMin, sqrtPriceMax);
|
|
2003
|
+
const virtualLt = balanceLt + mulDiv(liquidity, ONE, sqrtPriceMax);
|
|
2004
|
+
const virtualGt = balanceGt + mulDiv(liquidity, sqrtPriceMin, ONE);
|
|
2005
|
+
const sqrtPriceSpot = bigintSqrt(mulDiv(virtualGt, ONE * ONE, virtualLt));
|
|
2006
|
+
return {
|
|
2007
|
+
liquidity,
|
|
2008
|
+
sqrtPriceSpot
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
/**
|
|
2012
|
+
* Compute L from real balances and price bounds.
|
|
2013
|
+
* Mirrors XYCConcentrateArgsBuilder._computeL in XYCConcentrate.sol.
|
|
2014
|
+
*/
|
|
2015
|
+
function computeL(bLt, bGt, sqrtPriceMin, sqrtPriceMax) {
|
|
2016
|
+
const alpha = ONE - mulDiv(sqrtPriceMin, ONE, sqrtPriceMax);
|
|
2017
|
+
const beta = mulDiv(bLt, sqrtPriceMin, ONE) + mulDiv(bGt, ONE, sqrtPriceMax);
|
|
2018
|
+
const fourAC = mulDiv(4n * alpha, bLt, ONE) * bGt;
|
|
2019
|
+
const disc = beta * beta + fourAC;
|
|
2020
|
+
return mulDiv(beta + bigintSqrt(disc), ONE, 2n * alpha);
|
|
2021
|
+
}
|
|
2022
|
+
function mulDiv(a, b, c) {
|
|
2023
|
+
if (c === 0n) throw new Error("mulDiv: division by zero");
|
|
2024
|
+
return a * b / c;
|
|
1896
2025
|
}
|
|
1897
2026
|
|
|
1898
2027
|
//#endregion
|
|
@@ -1900,10 +2029,12 @@ function sqrt(value) {
|
|
|
1900
2029
|
var concentrate_exports = {};
|
|
1901
2030
|
__export(concentrate_exports, {
|
|
1902
2031
|
ConcentrateGrowLiquidity2DArgs: () => ConcentrateGrowLiquidity2DArgs,
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
2032
|
+
ONE_E18: () => ONE_E18,
|
|
2033
|
+
bigintSqrt: () => bigintSqrt,
|
|
2034
|
+
computeBalances: () => computeBalances,
|
|
2035
|
+
computeLiquidityAndPrice: () => computeLiquidityAndPrice,
|
|
2036
|
+
computeLiquidityFromAmounts: () => computeLiquidityFromAmounts,
|
|
2037
|
+
concentrateGrowLiquidity2D: () => concentrateGrowLiquidity2D
|
|
1907
2038
|
});
|
|
1908
2039
|
|
|
1909
2040
|
//#endregion
|
|
@@ -1931,7 +2062,7 @@ var DecayXDArgs = class DecayXDArgs {
|
|
|
1931
2062
|
static CODER = new DecayXDArgsCoder();
|
|
1932
2063
|
constructor(decayPeriod) {
|
|
1933
2064
|
this.decayPeriod = decayPeriod;
|
|
1934
|
-
(0,
|
|
2065
|
+
(0, assert.default)(decayPeriod >= 0n && decayPeriod <= __1inch_byte_utils.UINT_16_MAX, `Invalid decayPeriod value: ${decayPeriod}. Must be a valid uint16`);
|
|
1935
2066
|
}
|
|
1936
2067
|
/**
|
|
1937
2068
|
* Decodes hex data into DecayXDArgs instance
|
|
@@ -2054,8 +2185,8 @@ var MinRateArgs = class MinRateArgs {
|
|
|
2054
2185
|
constructor(rateLt, rateGt) {
|
|
2055
2186
|
this.rateLt = rateLt;
|
|
2056
2187
|
this.rateGt = rateGt;
|
|
2057
|
-
(0,
|
|
2058
|
-
(0,
|
|
2188
|
+
(0, assert.default)(rateLt >= 0n && rateLt <= __1inch_byte_utils.UINT_64_MAX, `Invalid rateLt: ${rateLt}. Must be a valid uint64`);
|
|
2189
|
+
(0, assert.default)(rateGt >= 0n && rateGt <= __1inch_byte_utils.UINT_64_MAX, `Invalid rateGt: ${rateGt}. Must be a valid uint64`);
|
|
2059
2190
|
}
|
|
2060
2191
|
static fromTokens(tokenA, tokenB, rateA, rateB) {
|
|
2061
2192
|
if (BigInt(tokenA.toString()) < BigInt(tokenB.toString())) return new MinRateArgs(rateA, rateB);
|
|
@@ -2104,14 +2235,14 @@ var DutchAuctionArgsCoder = class {
|
|
|
2104
2235
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2105
2236
|
builder.addUint40(args.startTime);
|
|
2106
2237
|
builder.addUint16(args.duration);
|
|
2107
|
-
builder.
|
|
2238
|
+
builder.addUint64(args.decayFactor);
|
|
2108
2239
|
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
2109
2240
|
}
|
|
2110
2241
|
decode(data) {
|
|
2111
2242
|
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2112
2243
|
const startTime = iter.nextUint40();
|
|
2113
2244
|
const duration = iter.nextUint16();
|
|
2114
|
-
const decayFactor = iter.
|
|
2245
|
+
const decayFactor = iter.nextUint64();
|
|
2115
2246
|
return new DutchAuctionArgs(startTime, duration, decayFactor);
|
|
2116
2247
|
}
|
|
2117
2248
|
};
|
|
@@ -2129,7 +2260,6 @@ var DutchAuctionArgsCoder = class {
|
|
|
2129
2260
|
* - Only works for 1=>0 swaps (token1 to token0)
|
|
2130
2261
|
*
|
|
2131
2262
|
* The decay factor determines the price reduction rate:
|
|
2132
|
-
* - 1.0e18 = no decay (constant price)
|
|
2133
2263
|
* - 0.999e18 = 0.1% decay per second
|
|
2134
2264
|
* - 0.99e18 = 1% decay per second
|
|
2135
2265
|
* - 0.9e18 = 10% decay per second
|
|
@@ -2148,16 +2278,16 @@ var DutchAuctionArgs = class DutchAuctionArgs {
|
|
|
2148
2278
|
/**
|
|
2149
2279
|
* startTime - auction start time (uint40)
|
|
2150
2280
|
* duration - auction duration in seconds (uint16)
|
|
2151
|
-
* decayFactor - price decay per second, 1e18 = no decay (
|
|
2281
|
+
* decayFactor - price decay per second, 1e18 = no decay (uint64)
|
|
2152
2282
|
**/
|
|
2153
2283
|
constructor(startTime, duration, decayFactor) {
|
|
2154
2284
|
this.startTime = startTime;
|
|
2155
2285
|
this.duration = duration;
|
|
2156
2286
|
this.decayFactor = decayFactor;
|
|
2157
|
-
(0,
|
|
2158
|
-
(0,
|
|
2159
|
-
(0,
|
|
2160
|
-
(0,
|
|
2287
|
+
(0, assert.default)(startTime >= 0n && startTime <= __1inch_byte_utils.UINT_40_MAX, `Invalid startTime: ${startTime}. Must be a valid uint40`);
|
|
2288
|
+
(0, assert.default)(duration >= 0n && duration <= __1inch_byte_utils.UINT_16_MAX, `Invalid duration: ${duration}. Must be a valid uint16`);
|
|
2289
|
+
(0, assert.default)(decayFactor >= 0n && decayFactor <= __1inch_byte_utils_dist_constants.UINT_64_MAX, `Invalid decayFactor: ${decayFactor}. Must be a valid uint64`);
|
|
2290
|
+
(0, assert.default)(decayFactor < 1e18, `Decay factor should be less than 1e18: ${decayFactor}`);
|
|
2161
2291
|
}
|
|
2162
2292
|
/**
|
|
2163
2293
|
* Decodes hex data into DutchAuctionArgs instance
|
|
@@ -2196,99 +2326,6 @@ __export(dutch_auction_exports, {
|
|
|
2196
2326
|
dutchAuctionBalanceOut1D: () => dutchAuctionBalanceOut1D
|
|
2197
2327
|
});
|
|
2198
2328
|
|
|
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
2329
|
//#endregion
|
|
2293
2330
|
//#region src/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.ts
|
|
2294
2331
|
var BaseFeeAdjusterArgsCoder = class {
|
|
@@ -2344,10 +2381,10 @@ var BaseFeeAdjusterArgs = class BaseFeeAdjusterArgs {
|
|
|
2344
2381
|
this.ethToToken1Price = ethToToken1Price;
|
|
2345
2382
|
this.gasAmount = gasAmount;
|
|
2346
2383
|
this.maxPriceDecay = maxPriceDecay;
|
|
2347
|
-
(0,
|
|
2348
|
-
(0,
|
|
2349
|
-
(0,
|
|
2350
|
-
(0,
|
|
2384
|
+
(0, assert.default)(baseGasPrice >= 0n && baseGasPrice <= __1inch_byte_utils.UINT_64_MAX, `Invalid baseGasPrice: ${baseGasPrice}. Must be a valid uint64`);
|
|
2385
|
+
(0, assert.default)(ethToToken1Price >= 0n && ethToToken1Price <= __1inch_byte_utils.UINT_96_MAX, `Invalid ethToToken1Price: ${ethToToken1Price}. Must be a valid uint96`);
|
|
2386
|
+
(0, assert.default)(gasAmount >= 0n && gasAmount <= __1inch_byte_utils.UINT_24_MAX, `Invalid gasAmount: ${gasAmount}. Must be a valid uint24`);
|
|
2387
|
+
(0, assert.default)(maxPriceDecay >= 0n && maxPriceDecay <= __1inch_byte_utils.UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
|
|
2351
2388
|
}
|
|
2352
2389
|
/**
|
|
2353
2390
|
* Decodes hex data into BaseFeeAdjusterArgs instance
|
|
@@ -2471,12 +2508,12 @@ var TWAPSwapArgs = class TWAPSwapArgs {
|
|
|
2471
2508
|
this.duration = duration;
|
|
2472
2509
|
this.priceBumpAfterIlliquidity = priceBumpAfterIlliquidity;
|
|
2473
2510
|
this.minTradeAmountOut = minTradeAmountOut;
|
|
2474
|
-
(0,
|
|
2475
|
-
(0,
|
|
2476
|
-
(0,
|
|
2477
|
-
(0,
|
|
2478
|
-
(0,
|
|
2479
|
-
(0,
|
|
2511
|
+
(0, assert.default)(balanceIn >= 0n && balanceIn <= __1inch_byte_utils.UINT_256_MAX, `Invalid balanceIn: ${balanceIn}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2512
|
+
(0, assert.default)(balanceOut >= 0n && balanceOut <= __1inch_byte_utils.UINT_256_MAX, `Invalid balanceOut: ${balanceOut}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2513
|
+
(0, assert.default)(startTime >= 0n && startTime <= __1inch_byte_utils.UINT_256_MAX, `Invalid startTime: ${startTime}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2514
|
+
(0, assert.default)(duration >= 0n && duration <= __1inch_byte_utils.UINT_256_MAX, `Invalid duration: ${duration}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2515
|
+
(0, assert.default)(priceBumpAfterIlliquidity >= 0n && priceBumpAfterIlliquidity <= __1inch_byte_utils.UINT_256_MAX, `Invalid priceBumpAfterIlliquidity: ${priceBumpAfterIlliquidity}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2516
|
+
(0, assert.default)(minTradeAmountOut >= 0n && minTradeAmountOut <= __1inch_byte_utils.UINT_256_MAX, `Invalid minTradeAmountOut: ${minTradeAmountOut}. Must be >= 0 and <= UINT_256_MAX`);
|
|
2480
2517
|
}
|
|
2481
2518
|
/**
|
|
2482
2519
|
* Decodes hex data into TWAPSwapArgs instance
|
|
@@ -2513,7 +2550,7 @@ __export(twap_swap_exports, {
|
|
|
2513
2550
|
});
|
|
2514
2551
|
|
|
2515
2552
|
//#endregion
|
|
2516
|
-
//#region src/swap-vm/instructions/fee/flat-fee-args-coder.ts
|
|
2553
|
+
//#region src/swap-vm/instructions/fee/flat-fee/flat-fee-args-coder.ts
|
|
2517
2554
|
var FlatFeeArgsCoder = class {
|
|
2518
2555
|
encode(args) {
|
|
2519
2556
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
@@ -2528,18 +2565,18 @@ var FlatFeeArgsCoder = class {
|
|
|
2528
2565
|
};
|
|
2529
2566
|
|
|
2530
2567
|
//#endregion
|
|
2531
|
-
//#region src/swap-vm/instructions/fee/flat-fee-args.ts
|
|
2568
|
+
//#region src/swap-vm/instructions/fee/flat-fee/flat-fee-args.ts
|
|
2532
2569
|
const FEE_100_PERCENT$1 = 1e9;
|
|
2533
2570
|
/**
|
|
2534
|
-
* Arguments for flat fee instructions (
|
|
2571
|
+
* Arguments for flat fee instructions (flatFeeAmountInXD)
|
|
2535
2572
|
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L66
|
|
2536
2573
|
**/
|
|
2537
2574
|
var FlatFeeArgs = class FlatFeeArgs {
|
|
2538
2575
|
static CODER = new FlatFeeArgsCoder();
|
|
2539
2576
|
constructor(fee) {
|
|
2540
2577
|
this.fee = fee;
|
|
2541
|
-
(0,
|
|
2542
|
-
(0,
|
|
2578
|
+
(0, assert.default)(fee >= 0n && fee <= __1inch_byte_utils.UINT_32_MAX, `Invalid fee: ${fee}. Must be a valid uint32`);
|
|
2579
|
+
(0, assert.default)(fee <= BigInt(FEE_100_PERCENT$1), `Fee out of range: ${fee}. Must be <= ${FEE_100_PERCENT$1}`);
|
|
2543
2580
|
}
|
|
2544
2581
|
/**
|
|
2545
2582
|
* Decodes hex data into FlatFeeArgs instance
|
|
@@ -2570,7 +2607,7 @@ var FlatFeeArgs = class FlatFeeArgs {
|
|
|
2570
2607
|
};
|
|
2571
2608
|
|
|
2572
2609
|
//#endregion
|
|
2573
|
-
//#region src/swap-vm/instructions/fee/protocol-fee-args-coder.ts
|
|
2610
|
+
//#region src/swap-vm/instructions/fee/protocol-fee/protocol-fee-args-coder.ts
|
|
2574
2611
|
var ProtocolFeeArgsCoder = class {
|
|
2575
2612
|
encode(args) {
|
|
2576
2613
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
@@ -2587,11 +2624,11 @@ var ProtocolFeeArgsCoder = class {
|
|
|
2587
2624
|
};
|
|
2588
2625
|
|
|
2589
2626
|
//#endregion
|
|
2590
|
-
//#region src/swap-vm/instructions/fee/protocol-fee-args.ts
|
|
2627
|
+
//#region src/swap-vm/instructions/fee/protocol-fee/protocol-fee-args.ts
|
|
2591
2628
|
const FEE_100_PERCENT = 1e9;
|
|
2592
2629
|
/**
|
|
2593
|
-
* Arguments for protocol fee instructions (
|
|
2594
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#
|
|
2630
|
+
* Arguments for protocol fee instructions (protocolFeeAmountInXD, aquaProtocolFeeAmountInXD)
|
|
2631
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L101
|
|
2595
2632
|
**/
|
|
2596
2633
|
var ProtocolFeeArgs = class ProtocolFeeArgs {
|
|
2597
2634
|
static CODER = new ProtocolFeeArgsCoder();
|
|
@@ -2602,8 +2639,8 @@ var ProtocolFeeArgs = class ProtocolFeeArgs {
|
|
|
2602
2639
|
constructor(fee, to) {
|
|
2603
2640
|
this.fee = fee;
|
|
2604
2641
|
this.to = to;
|
|
2605
|
-
(0,
|
|
2606
|
-
(0,
|
|
2642
|
+
(0, assert.default)(fee >= 0n && fee <= __1inch_byte_utils.UINT_32_MAX, `Invalid fee: ${fee}. Must be a valid uint32`);
|
|
2643
|
+
(0, assert.default)(fee <= BigInt(FEE_100_PERCENT), `Fee out of range: ${fee}. Must be <= ${FEE_100_PERCENT}`);
|
|
2607
2644
|
}
|
|
2608
2645
|
/**
|
|
2609
2646
|
* Decodes hex data into ProtocolFeeArgs instance
|
|
@@ -2638,50 +2675,110 @@ var ProtocolFeeArgs = class ProtocolFeeArgs {
|
|
|
2638
2675
|
}
|
|
2639
2676
|
};
|
|
2640
2677
|
|
|
2678
|
+
//#endregion
|
|
2679
|
+
//#region src/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args-coder.ts
|
|
2680
|
+
var DynamicProtocolFeeArgsCoder = class {
|
|
2681
|
+
encode(args) {
|
|
2682
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2683
|
+
builder.addAddress(args.feeProvider.toString());
|
|
2684
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
2685
|
+
}
|
|
2686
|
+
decode(data) {
|
|
2687
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
2688
|
+
const feeProvider = new __1inch_sdk_core.Address(iter.nextAddress());
|
|
2689
|
+
return new DynamicProtocolFeeArgs(feeProvider);
|
|
2690
|
+
}
|
|
2691
|
+
};
|
|
2692
|
+
|
|
2693
|
+
//#endregion
|
|
2694
|
+
//#region src/swap-vm/instructions/fee/dynamic-protocol-fee/dynamic-protocol-fee-args.ts
|
|
2695
|
+
/**
|
|
2696
|
+
* Arguments for dynamic protocol fee instructions (dynamicProtocolFeeAmountInXD, aquaDynamicProtocolFeeAmountInXD).
|
|
2697
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol
|
|
2698
|
+
**/
|
|
2699
|
+
var DynamicProtocolFeeArgs = class DynamicProtocolFeeArgs {
|
|
2700
|
+
static CODER = new DynamicProtocolFeeArgsCoder();
|
|
2701
|
+
constructor(feeProvider) {
|
|
2702
|
+
this.feeProvider = feeProvider;
|
|
2703
|
+
(0, assert.default)(!feeProvider.isZero(), "Invalid feeProvider. Must be non zero address");
|
|
2704
|
+
}
|
|
2705
|
+
static decode(data) {
|
|
2706
|
+
return DynamicProtocolFeeArgs.CODER.decode(data);
|
|
2707
|
+
}
|
|
2708
|
+
toJSON() {
|
|
2709
|
+
return { feeProvider: this.feeProvider.toString() };
|
|
2710
|
+
}
|
|
2711
|
+
};
|
|
2712
|
+
|
|
2641
2713
|
//#endregion
|
|
2642
2714
|
//#region src/swap-vm/instructions/fee/opcodes.ts
|
|
2643
2715
|
/**
|
|
2644
2716
|
* Applies fee to amountIn
|
|
2645
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#
|
|
2717
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L72
|
|
2646
2718
|
**/
|
|
2647
2719
|
const flatFeeAmountInXD = new Opcode(Symbol("Fee.flatFeeAmountInXD"), FlatFeeArgs.CODER);
|
|
2648
2720
|
/**
|
|
2721
|
+
* Protocol fee on amountIn (feeBps + to). Fee transferred from maker to recipient.
|
|
2722
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L101
|
|
2723
|
+
**/
|
|
2724
|
+
const protocolFeeAmountInXD = new Opcode(Symbol("Fee.protocolFeeAmountInXD"), ProtocolFeeArgs.CODER);
|
|
2725
|
+
/**
|
|
2726
|
+
* Protocol fee on amountIn for Aqua (feeBps + to). Pulls from maker's Aqua balance.
|
|
2727
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L121
|
|
2728
|
+
**/
|
|
2729
|
+
const aquaProtocolFeeAmountInXD = new Opcode(Symbol("Fee.aquaProtocolFeeAmountInXD"), ProtocolFeeArgs.CODER);
|
|
2730
|
+
/**
|
|
2731
|
+
* Dynamic protocol fee: args = feeProvider address (20 bytes).
|
|
2732
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L148
|
|
2733
|
+
**/
|
|
2734
|
+
const dynamicProtocolFeeAmountInXD = new Opcode(Symbol("Fee.dynamicProtocolFeeAmountInXD"), DynamicProtocolFeeArgs.CODER);
|
|
2735
|
+
/**
|
|
2736
|
+
* Dynamic protocol fee for Aqua: args = feeProvider address (20 bytes).
|
|
2737
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L197
|
|
2738
|
+
**/
|
|
2739
|
+
const aquaDynamicProtocolFeeAmountInXD = new Opcode(Symbol("Fee.aquaDynamicProtocolFeeAmountInXD"), DynamicProtocolFeeArgs.CODER);
|
|
2740
|
+
/**
|
|
2649
2741
|
* Applies fee to amountOut
|
|
2650
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/
|
|
2742
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L40
|
|
2651
2743
|
**/
|
|
2652
|
-
const flatFeeAmountOutXD = new Opcode(Symbol("
|
|
2744
|
+
const flatFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.flatFeeAmountOutXD"), FlatFeeArgs.CODER);
|
|
2653
2745
|
/**
|
|
2654
2746
|
* Applies progressive fee to amountIn
|
|
2655
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/
|
|
2747
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L46
|
|
2656
2748
|
**/
|
|
2657
|
-
const progressiveFeeInXD = new Opcode(Symbol("
|
|
2749
|
+
const progressiveFeeInXD = new Opcode(Symbol("FeeExperimental.progressiveFeeInXD"), FlatFeeArgs.CODER);
|
|
2658
2750
|
/**
|
|
2659
2751
|
* Applies progressive fee to amountOut
|
|
2660
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/
|
|
2752
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L74
|
|
2661
2753
|
**/
|
|
2662
|
-
const progressiveFeeOutXD = new Opcode(Symbol("
|
|
2754
|
+
const progressiveFeeOutXD = new Opcode(Symbol("FeeExperimental.progressiveFeeOutXD"), FlatFeeArgs.CODER);
|
|
2663
2755
|
/**
|
|
2664
|
-
*
|
|
2665
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/
|
|
2756
|
+
* Protocol fee on amountOut (feeBps + to). Fee transferred from maker to recipient.
|
|
2757
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L107
|
|
2666
2758
|
**/
|
|
2667
|
-
const protocolFeeAmountOutXD = new Opcode(Symbol("
|
|
2759
|
+
const protocolFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.protocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
|
|
2668
2760
|
/**
|
|
2669
|
-
*
|
|
2670
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/
|
|
2761
|
+
* Protocol fee on amountOut (feeBps + to) for Aqua (feeBps + to). Pulls from maker's Aqua balance.
|
|
2762
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/FeeExperimental.sol#L122
|
|
2671
2763
|
**/
|
|
2672
|
-
const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("
|
|
2764
|
+
const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.aquaProtocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
|
|
2673
2765
|
|
|
2674
2766
|
//#endregion
|
|
2675
2767
|
//#region src/swap-vm/instructions/fee/index.ts
|
|
2676
2768
|
var fee_exports = {};
|
|
2677
2769
|
__export(fee_exports, {
|
|
2770
|
+
DynamicProtocolFeeArgs: () => DynamicProtocolFeeArgs,
|
|
2678
2771
|
FlatFeeArgs: () => FlatFeeArgs,
|
|
2679
2772
|
ProtocolFeeArgs: () => ProtocolFeeArgs,
|
|
2773
|
+
aquaDynamicProtocolFeeAmountInXD: () => aquaDynamicProtocolFeeAmountInXD,
|
|
2774
|
+
aquaProtocolFeeAmountInXD: () => aquaProtocolFeeAmountInXD,
|
|
2680
2775
|
aquaProtocolFeeAmountOutXD: () => aquaProtocolFeeAmountOutXD,
|
|
2776
|
+
dynamicProtocolFeeAmountInXD: () => dynamicProtocolFeeAmountInXD,
|
|
2681
2777
|
flatFeeAmountInXD: () => flatFeeAmountInXD,
|
|
2682
2778
|
flatFeeAmountOutXD: () => flatFeeAmountOutXD,
|
|
2683
2779
|
progressiveFeeInXD: () => progressiveFeeInXD,
|
|
2684
2780
|
progressiveFeeOutXD: () => progressiveFeeOutXD,
|
|
2781
|
+
protocolFeeAmountInXD: () => protocolFeeAmountInXD,
|
|
2685
2782
|
protocolFeeAmountOutXD: () => protocolFeeAmountOutXD
|
|
2686
2783
|
});
|
|
2687
2784
|
|
|
@@ -2749,82 +2846,194 @@ __export(extruction_exports, {
|
|
|
2749
2846
|
});
|
|
2750
2847
|
|
|
2751
2848
|
//#endregion
|
|
2752
|
-
//#region src/swap-vm/instructions/
|
|
2753
|
-
var
|
|
2849
|
+
//#region src/swap-vm/instructions/pegged-swap/pegged-swap-args-coder.ts
|
|
2850
|
+
var PeggedSwapArgsCoder = class {
|
|
2754
2851
|
encode(args) {
|
|
2755
2852
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2756
|
-
builder.
|
|
2757
|
-
builder.
|
|
2853
|
+
builder.addUint256(args.x0);
|
|
2854
|
+
builder.addUint256(args.y0);
|
|
2855
|
+
builder.addUint256(args.linearWidth);
|
|
2758
2856
|
builder.addUint256(args.rateLt);
|
|
2759
2857
|
builder.addUint256(args.rateGt);
|
|
2760
|
-
return new __1inch_sdk_core.HexString(
|
|
2858
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
2761
2859
|
}
|
|
2762
2860
|
decode(data) {
|
|
2763
2861
|
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2764
|
-
const
|
|
2765
|
-
const
|
|
2766
|
-
const
|
|
2767
|
-
const
|
|
2768
|
-
|
|
2862
|
+
const x0 = BigInt(iter.nextUint256());
|
|
2863
|
+
const y0 = BigInt(iter.nextUint256());
|
|
2864
|
+
const linearWidth = BigInt(iter.nextUint256());
|
|
2865
|
+
const rateLt = BigInt(iter.nextUint256());
|
|
2866
|
+
const rateGt = BigInt(iter.nextUint256());
|
|
2867
|
+
return new PeggedSwapArgs(x0, y0, linearWidth, rateLt, rateGt);
|
|
2769
2868
|
}
|
|
2770
2869
|
};
|
|
2771
2870
|
|
|
2772
2871
|
//#endregion
|
|
2773
|
-
//#region src/swap-vm/instructions/
|
|
2872
|
+
//#region src/swap-vm/instructions/pegged-swap/rate-resolver.ts
|
|
2873
|
+
function resolveRate(tokenADecimals, tokenBDecimals) {
|
|
2874
|
+
if (tokenADecimals === tokenBDecimals) return 1n;
|
|
2875
|
+
if (tokenADecimals > tokenBDecimals) return 1n;
|
|
2876
|
+
return 10n ** BigInt(tokenBDecimals - tokenADecimals);
|
|
2877
|
+
}
|
|
2878
|
+
|
|
2879
|
+
//#endregion
|
|
2880
|
+
//#region src/swap-vm/instructions/pegged-swap/pegged-swap-args.ts
|
|
2774
2881
|
/**
|
|
2775
|
-
* Arguments for
|
|
2882
|
+
* Arguments for PeggedSwap._peggedSwapGrowPriceRange2D.
|
|
2883
|
+
* 5 × uint256: x0, y0, linearWidth, rateLt, rateGt (160 bytes).
|
|
2884
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/PeggedSwap.sol
|
|
2776
2885
|
**/
|
|
2777
|
-
var
|
|
2778
|
-
static CODER = new
|
|
2886
|
+
var PeggedSwapArgs = class PeggedSwapArgs {
|
|
2887
|
+
static CODER = new PeggedSwapArgsCoder();
|
|
2779
2888
|
/**
|
|
2780
|
-
*
|
|
2781
|
-
*
|
|
2782
|
-
*
|
|
2783
|
-
*
|
|
2889
|
+
* x0 - Initial X reserve (normalization factor) = initial_balance_X * rateLt (or rateGt)
|
|
2890
|
+
* y0 - Initial Y reserve (normalization factor) = initial_balance_Y * rateGt (or rateLt)
|
|
2891
|
+
* linearWidth - Linear component coefficient A scaled by 1e27 (e.g., 0.8e27 for A=0.8)
|
|
2892
|
+
* rateLt - Rate multiplier for token with LOWER address
|
|
2893
|
+
* rateGt - Rate multiplier for token with GREATER address
|
|
2894
|
+
* > For equal decimals (e.g., both 18): rateLt = rateGt = 1
|
|
2895
|
+
* > For 18 vs 6 decimals: rate18 = 1, rate6 = 1e12 (to scale up to common precision)
|
|
2784
2896
|
**/
|
|
2785
|
-
constructor(
|
|
2786
|
-
this.
|
|
2787
|
-
this.
|
|
2897
|
+
constructor(x0, y0, linearWidth, rateLt, rateGt) {
|
|
2898
|
+
this.x0 = x0;
|
|
2899
|
+
this.y0 = y0;
|
|
2900
|
+
this.linearWidth = linearWidth;
|
|
2788
2901
|
this.rateLt = rateLt;
|
|
2789
2902
|
this.rateGt = rateGt;
|
|
2790
|
-
(0,
|
|
2791
|
-
(0,
|
|
2792
|
-
(0,
|
|
2793
|
-
(0,
|
|
2903
|
+
(0, assert.default)(x0 > 0n && y0 > 0n, "Reserves cannot be zero");
|
|
2904
|
+
(0, assert.default)(x0 <= __1inch_byte_utils.UINT_256_MAX, `Invalid x0: ${x0}`);
|
|
2905
|
+
(0, assert.default)(y0 <= __1inch_byte_utils.UINT_256_MAX, `Invalid y0: ${y0}`);
|
|
2906
|
+
(0, assert.default)(linearWidth <= 2n * 10n ** 27n, `Invalid linearWidth: ${linearWidth}`);
|
|
2907
|
+
(0, assert.default)(rateLt > 0n && rateLt <= __1inch_byte_utils.UINT_256_MAX, `Invalid rateLt: ${rateLt}. Must be positive and <= UINT_256_MAX`);
|
|
2908
|
+
(0, assert.default)(rateGt > 0n && rateGt <= __1inch_byte_utils.UINT_256_MAX, `Invalid rateGt: ${rateGt}. Must be positive and <= UINT_256_MAX`);
|
|
2909
|
+
}
|
|
2910
|
+
static fromTokens(tokenA, tokenB, linearWidth) {
|
|
2911
|
+
const tokenARate = resolveRate(tokenA.decimals, tokenB.decimals);
|
|
2912
|
+
const tokenBRate = resolveRate(tokenB.decimals, tokenA.decimals);
|
|
2913
|
+
if (BigInt(tokenA.address.toString()) < BigInt(tokenB.address.toString())) return new PeggedSwapArgs(tokenA.reserve * tokenARate, tokenB.reserve * tokenBRate, linearWidth, tokenARate, tokenBRate);
|
|
2914
|
+
return new PeggedSwapArgs(tokenB.reserve * tokenBRate, tokenA.reserve * tokenARate, linearWidth, tokenBRate, tokenARate);
|
|
2915
|
+
}
|
|
2916
|
+
static decode(data) {
|
|
2917
|
+
return PeggedSwapArgs.CODER.decode(data);
|
|
2918
|
+
}
|
|
2919
|
+
toJSON() {
|
|
2920
|
+
return {
|
|
2921
|
+
x0: this.x0.toString(),
|
|
2922
|
+
y0: this.y0.toString(),
|
|
2923
|
+
linearWidth: this.linearWidth.toString(),
|
|
2924
|
+
rateLt: this.rateLt.toString(),
|
|
2925
|
+
rateGt: this.rateGt.toString()
|
|
2926
|
+
};
|
|
2794
2927
|
}
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2928
|
+
};
|
|
2929
|
+
|
|
2930
|
+
//#endregion
|
|
2931
|
+
//#region src/swap-vm/instructions/pegged-swap/opcodes.ts
|
|
2932
|
+
/**
|
|
2933
|
+
* PeggedSwap - Square-root linear swap curve for pegged assets
|
|
2934
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/PeggedSwap.sol
|
|
2935
|
+
**/
|
|
2936
|
+
const peggedSwapGrowPriceRange2D = new Opcode(Symbol("PeggedSwap.peggedSwapGrowPriceRange2D"), PeggedSwapArgs.CODER);
|
|
2937
|
+
|
|
2938
|
+
//#endregion
|
|
2939
|
+
//#region src/swap-vm/instructions/pegged-swap/index.ts
|
|
2940
|
+
var pegged_swap_exports = {};
|
|
2941
|
+
__export(pegged_swap_exports, {
|
|
2942
|
+
PeggedSwapArgs: () => PeggedSwapArgs,
|
|
2943
|
+
peggedSwapGrowPriceRange2D: () => peggedSwapGrowPriceRange2D
|
|
2944
|
+
});
|
|
2945
|
+
|
|
2946
|
+
//#endregion
|
|
2947
|
+
//#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.ts
|
|
2948
|
+
var OraclePriceAdjusterArgsCoder = class {
|
|
2949
|
+
encode(args) {
|
|
2950
|
+
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2951
|
+
builder.addUint64(args.maxPriceDecay);
|
|
2952
|
+
builder.addUint16(args.maxStaleness);
|
|
2953
|
+
builder.addUint8(args.oracleDecimals);
|
|
2954
|
+
builder.addAddress(args.oracleAddress.toString());
|
|
2955
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
2956
|
+
}
|
|
2957
|
+
decode(data) {
|
|
2958
|
+
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
2959
|
+
const maxPriceDecay = iter.nextUint64();
|
|
2960
|
+
const maxStaleness = iter.nextUint16();
|
|
2961
|
+
const oracleDecimals = iter.nextUint8();
|
|
2962
|
+
const oracleAddress = new __1inch_sdk_core.Address(iter.nextAddress());
|
|
2963
|
+
return new OraclePriceAdjusterArgs(BigInt(maxPriceDecay), BigInt(maxStaleness), BigInt(oracleDecimals), oracleAddress);
|
|
2964
|
+
}
|
|
2965
|
+
};
|
|
2966
|
+
|
|
2967
|
+
//#endregion
|
|
2968
|
+
//#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.ts
|
|
2969
|
+
/**
|
|
2970
|
+
* @notice Oracle Price Adjuster instruction for dynamic price adjustment based on Chainlink price feeds
|
|
2971
|
+
* @dev Adjusts swap prices to match Chainlink oracle prices within safe bounds:
|
|
2972
|
+
* - Works only for 1=>0 swaps (token1 to token0), compatible with LimitSwap and other swap instructions
|
|
2973
|
+
* - Fetches current market price from a Chainlink oracle (AggregatorV3Interface)
|
|
2974
|
+
* - Adjusts the swap price towards the oracle price within maxPriceDecay limits
|
|
2975
|
+
* - Ensures the adjustment is always favorable for the taker
|
|
2976
|
+
* - Handles different decimal places from Chainlink oracles (e.g., 8 decimals for USD prices)
|
|
2977
|
+
*
|
|
2978
|
+
* This creates adaptive orders that automatically track market prices while maintaining
|
|
2979
|
+
* safety bounds to prevent excessive slippage or manipulation.
|
|
2980
|
+
*
|
|
2981
|
+
* Example usage:
|
|
2982
|
+
* 1. LimitSwap sets base price: 1 ETH for 3000 USDC
|
|
2983
|
+
* 2. OraclePriceAdjuster with Chainlink ETH/USD oracle: 1 ETH = 3100 USD, maxPriceDecay=0.95e18 (5% max)
|
|
2984
|
+
* 3. exactIn: Taker gets more ETH (up to 5% improvement)
|
|
2985
|
+
* 4. exactOut: Taker pays less USDC (up to 5% discount)
|
|
2986
|
+
*
|
|
2987
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
|
|
2988
|
+
*/
|
|
2989
|
+
var OraclePriceAdjusterArgs = class OraclePriceAdjusterArgs {
|
|
2990
|
+
static CODER = new OraclePriceAdjusterArgsCoder();
|
|
2991
|
+
/**
|
|
2992
|
+
* maxPriceDecay - maximum price decay coefficient (uint64)
|
|
2993
|
+
* maxStaleness - maximum allowed oracle data staleness in seconds (uint16
|
|
2994
|
+
* oracleDecimals - decimals used by the oracle (uint8)
|
|
2995
|
+
* oracleAddress - address of the Chainlink price oracle contract
|
|
2996
|
+
**/
|
|
2997
|
+
constructor(maxPriceDecay, maxStaleness, oracleDecimals, oracleAddress) {
|
|
2998
|
+
this.maxPriceDecay = maxPriceDecay;
|
|
2999
|
+
this.maxStaleness = maxStaleness;
|
|
3000
|
+
this.oracleDecimals = oracleDecimals;
|
|
3001
|
+
this.oracleAddress = oracleAddress;
|
|
3002
|
+
(0, assert.default)(maxPriceDecay >= 0n && maxPriceDecay <= __1inch_byte_utils.UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
|
|
3003
|
+
(0, assert.default)(maxPriceDecay < 1e18, `Max price decay should be less than 1e18: ${maxPriceDecay}`);
|
|
3004
|
+
(0, assert.default)(maxStaleness >= 0n && maxStaleness <= __1inch_byte_utils.UINT_16_MAX, `Invalid maxStaleness: ${maxStaleness}. Must be a valid uint16`);
|
|
3005
|
+
(0, assert.default)(oracleDecimals >= 0n && oracleDecimals <= __1inch_byte_utils.UINT_8_MAX, `Invalid oracleDecimals: ${oracleDecimals}. Must be a valid uint8`);
|
|
2798
3006
|
}
|
|
2799
3007
|
/**
|
|
2800
|
-
* Decodes hex data into
|
|
3008
|
+
* Decodes hex data into OraclePriceAdjusterArgs instance
|
|
2801
3009
|
**/
|
|
2802
3010
|
static decode(data) {
|
|
2803
|
-
return
|
|
3011
|
+
return OraclePriceAdjusterArgs.CODER.decode(data);
|
|
2804
3012
|
}
|
|
2805
3013
|
toJSON() {
|
|
2806
3014
|
return {
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
3015
|
+
maxPriceDecay: this.maxPriceDecay.toString(),
|
|
3016
|
+
maxStaleness: this.maxStaleness.toString(),
|
|
3017
|
+
oracleDecimals: this.oracleDecimals.toString(),
|
|
3018
|
+
oracleAddress: this.oracleAddress.toString()
|
|
2811
3019
|
};
|
|
2812
3020
|
}
|
|
2813
3021
|
};
|
|
2814
3022
|
|
|
2815
3023
|
//#endregion
|
|
2816
|
-
//#region src/swap-vm/instructions/
|
|
3024
|
+
//#region src/swap-vm/instructions/oracle-price-adjuster/opcodes.ts
|
|
2817
3025
|
/**
|
|
2818
|
-
*
|
|
3026
|
+
* Adjusts swap prices based on Chainlink oracle feeds
|
|
3027
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
|
|
2819
3028
|
**/
|
|
2820
|
-
const
|
|
3029
|
+
const oraclePriceAdjuster1D = new Opcode(Symbol("OraclePriceAdjuster.oraclePriceAdjuster1D"), OraclePriceAdjusterArgs.CODER);
|
|
2821
3030
|
|
|
2822
3031
|
//#endregion
|
|
2823
|
-
//#region src/swap-vm/instructions/
|
|
2824
|
-
var
|
|
2825
|
-
__export(
|
|
2826
|
-
|
|
2827
|
-
|
|
3032
|
+
//#region src/swap-vm/instructions/oracle-price-adjuster/index.ts
|
|
3033
|
+
var oracle_price_adjuster_exports = {};
|
|
3034
|
+
__export(oracle_price_adjuster_exports, {
|
|
3035
|
+
OraclePriceAdjusterArgs: () => OraclePriceAdjusterArgs,
|
|
3036
|
+
oraclePriceAdjuster1D: () => oraclePriceAdjuster1D
|
|
2828
3037
|
});
|
|
2829
3038
|
|
|
2830
3039
|
//#endregion
|
|
@@ -2846,7 +3055,8 @@ __export(instructions_exports, {
|
|
|
2846
3055
|
limitSwap: () => limit_swap_exports,
|
|
2847
3056
|
minRate: () => min_rate_exports,
|
|
2848
3057
|
oraclePriceAdjuster: () => oracle_price_adjuster_exports,
|
|
2849
|
-
|
|
3058
|
+
peggedSwap: () => pegged_swap_exports,
|
|
3059
|
+
stableSwap: () => pegged_swap_exports,
|
|
2850
3060
|
twapSwap: () => twap_swap_exports,
|
|
2851
3061
|
xycSwap: () => xyc_swap_exports
|
|
2852
3062
|
});
|
|
@@ -2878,7 +3088,6 @@ const _allInstructions = [
|
|
|
2878
3088
|
invalidateTokenIn1D,
|
|
2879
3089
|
invalidateTokenOut1D,
|
|
2880
3090
|
xycSwapXD,
|
|
2881
|
-
concentrateGrowLiquidityXD,
|
|
2882
3091
|
concentrateGrowLiquidity2D,
|
|
2883
3092
|
decayXD,
|
|
2884
3093
|
limitSwap1D,
|
|
@@ -2887,7 +3096,6 @@ const _allInstructions = [
|
|
|
2887
3096
|
adjustMinRate1D,
|
|
2888
3097
|
dutchAuctionBalanceIn1D,
|
|
2889
3098
|
dutchAuctionBalanceOut1D,
|
|
2890
|
-
oraclePriceAdjuster1D,
|
|
2891
3099
|
baseFeeAdjuster1D,
|
|
2892
3100
|
twap,
|
|
2893
3101
|
extruction,
|
|
@@ -2897,7 +3105,12 @@ const _allInstructions = [
|
|
|
2897
3105
|
progressiveFeeInXD,
|
|
2898
3106
|
progressiveFeeOutXD,
|
|
2899
3107
|
protocolFeeAmountOutXD,
|
|
2900
|
-
aquaProtocolFeeAmountOutXD
|
|
3108
|
+
aquaProtocolFeeAmountOutXD,
|
|
3109
|
+
peggedSwapGrowPriceRange2D,
|
|
3110
|
+
protocolFeeAmountInXD,
|
|
3111
|
+
aquaProtocolFeeAmountInXD,
|
|
3112
|
+
dynamicProtocolFeeAmountInXD,
|
|
3113
|
+
aquaDynamicProtocolFeeAmountInXD
|
|
2901
3114
|
];
|
|
2902
3115
|
/**
|
|
2903
3116
|
* Aqua opcodes array - matching AquaSwapVM contract (29 opcodes)
|
|
@@ -2922,16 +3135,21 @@ const aquaInstructions = [
|
|
|
2922
3135
|
onlyTakerTokenBalanceGte,
|
|
2923
3136
|
onlyTakerTokenSupplyShareGte,
|
|
2924
3137
|
xycSwapXD,
|
|
2925
|
-
concentrateGrowLiquidityXD,
|
|
2926
3138
|
concentrateGrowLiquidity2D,
|
|
2927
3139
|
decayXD,
|
|
2928
3140
|
salt,
|
|
2929
3141
|
flatFeeAmountInXD,
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
3142
|
+
EMPTY_OPCODE,
|
|
3143
|
+
EMPTY_OPCODE,
|
|
3144
|
+
EMPTY_OPCODE,
|
|
3145
|
+
EMPTY_OPCODE,
|
|
3146
|
+
EMPTY_OPCODE,
|
|
3147
|
+
protocolFeeAmountInXD,
|
|
3148
|
+
aquaProtocolFeeAmountInXD,
|
|
3149
|
+
dynamicProtocolFeeAmountInXD,
|
|
3150
|
+
aquaDynamicProtocolFeeAmountInXD,
|
|
3151
|
+
peggedSwapGrowPriceRange2D,
|
|
3152
|
+
extruction
|
|
2935
3153
|
];
|
|
2936
3154
|
|
|
2937
3155
|
//#endregion
|
|
@@ -3233,17 +3451,17 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3233
3451
|
return this;
|
|
3234
3452
|
}
|
|
3235
3453
|
/**
|
|
3236
|
-
* Concentrates liquidity within price bounds for
|
|
3454
|
+
* Concentrates liquidity within price bounds for two tokens
|
|
3237
3455
|
**/
|
|
3238
|
-
|
|
3239
|
-
super.add(
|
|
3456
|
+
concentrateGrowLiquidity2D(data) {
|
|
3457
|
+
super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.sqrtPriceMin, data.sqrtPriceMax)));
|
|
3240
3458
|
return this;
|
|
3241
3459
|
}
|
|
3242
3460
|
/**
|
|
3243
|
-
*
|
|
3461
|
+
* Square-root linear swap curve for pegged assets
|
|
3244
3462
|
**/
|
|
3245
|
-
|
|
3246
|
-
super.add(
|
|
3463
|
+
peggedSwapGrowPriceRange2D(data) {
|
|
3464
|
+
super.add(peggedSwapGrowPriceRange2D.createIx(new PeggedSwapArgs(data.x0, data.y0, data.linearWidth, data.rateLt, data.rateGt)));
|
|
3247
3465
|
return this;
|
|
3248
3466
|
}
|
|
3249
3467
|
/**
|
|
@@ -3296,13 +3514,6 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3296
3514
|
return this;
|
|
3297
3515
|
}
|
|
3298
3516
|
/**
|
|
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
3517
|
* Adjusts swap prices based on network gas costs
|
|
3307
3518
|
**/
|
|
3308
3519
|
baseFeeAdjuster1D(data) {
|
|
@@ -3352,6 +3563,13 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3352
3563
|
return this;
|
|
3353
3564
|
}
|
|
3354
3565
|
/**
|
|
3566
|
+
* Applies protocol fee to amountIn with direct transfer
|
|
3567
|
+
**/
|
|
3568
|
+
protocolFeeAmountInXD(data) {
|
|
3569
|
+
super.add(protocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3570
|
+
return this;
|
|
3571
|
+
}
|
|
3572
|
+
/**
|
|
3355
3573
|
* Applies protocol fee to amountOut with direct transfer
|
|
3356
3574
|
**/
|
|
3357
3575
|
protocolFeeAmountOutXD(data) {
|
|
@@ -3359,6 +3577,13 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3359
3577
|
return this;
|
|
3360
3578
|
}
|
|
3361
3579
|
/**
|
|
3580
|
+
* Applies protocol fee to amountIn through Aqua protocol
|
|
3581
|
+
**/
|
|
3582
|
+
aquaProtocolFeeAmountInXD(data) {
|
|
3583
|
+
super.add(aquaProtocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3584
|
+
return this;
|
|
3585
|
+
}
|
|
3586
|
+
/**
|
|
3362
3587
|
* Applies protocol fee to amountOut through Aqua protocol
|
|
3363
3588
|
**/
|
|
3364
3589
|
aquaProtocolFeeAmountOutXD(data) {
|
|
@@ -3366,6 +3591,20 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3366
3591
|
return this;
|
|
3367
3592
|
}
|
|
3368
3593
|
/**
|
|
3594
|
+
* Applies protocol fee, fetched from external contract, to amountIn with direct transfer
|
|
3595
|
+
**/
|
|
3596
|
+
dynamicProtocolFeeAmountInXD(data) {
|
|
3597
|
+
super.add(dynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
|
|
3598
|
+
return this;
|
|
3599
|
+
}
|
|
3600
|
+
/**
|
|
3601
|
+
* Applies protocol fee, fetched from external contract, to amountIn through Aqua protocol
|
|
3602
|
+
**/
|
|
3603
|
+
aquaDynamicProtocolFeeAmountInXD(data) {
|
|
3604
|
+
super.add(aquaDynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
|
|
3605
|
+
return this;
|
|
3606
|
+
}
|
|
3607
|
+
/**
|
|
3369
3608
|
* DEBUG: Prints current swap registers (amounts and tokens)
|
|
3370
3609
|
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3371
3610
|
*/
|
|
@@ -3501,17 +3740,17 @@ var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
|
|
|
3501
3740
|
return this;
|
|
3502
3741
|
}
|
|
3503
3742
|
/**
|
|
3504
|
-
* Concentrates liquidity within price bounds for
|
|
3743
|
+
* Concentrates liquidity within price bounds for two tokens
|
|
3505
3744
|
**/
|
|
3506
|
-
|
|
3507
|
-
super.add(
|
|
3745
|
+
concentrateGrowLiquidity2D(data) {
|
|
3746
|
+
super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.sqrtPriceMin, data.sqrtPriceMax)));
|
|
3508
3747
|
return this;
|
|
3509
3748
|
}
|
|
3510
3749
|
/**
|
|
3511
|
-
*
|
|
3750
|
+
* Square-root linear swap curve for pegged assets
|
|
3512
3751
|
**/
|
|
3513
|
-
|
|
3514
|
-
super.add(
|
|
3752
|
+
peggedSwapGrowPriceRange2D(data) {
|
|
3753
|
+
super.add(peggedSwapGrowPriceRange2D.createIx(new PeggedSwapArgs(data.x0, data.y0, data.linearWidth, data.rateLt, data.rateGt)));
|
|
3515
3754
|
return this;
|
|
3516
3755
|
}
|
|
3517
3756
|
/**
|
|
@@ -3529,38 +3768,31 @@ var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
|
|
|
3529
3768
|
return this;
|
|
3530
3769
|
}
|
|
3531
3770
|
/**
|
|
3532
|
-
* Applies fee to
|
|
3771
|
+
* Applies protocol fee to amountIn with direct transfer
|
|
3533
3772
|
**/
|
|
3534
|
-
|
|
3535
|
-
super.add(
|
|
3536
|
-
return this;
|
|
3537
|
-
}
|
|
3538
|
-
/**
|
|
3539
|
-
* Applies progressive fee to amountIn
|
|
3540
|
-
**/
|
|
3541
|
-
progressiveFeeInXD(data) {
|
|
3542
|
-
super.add(progressiveFeeInXD.createIx(new FlatFeeArgs(data.fee)));
|
|
3773
|
+
protocolFeeAmountInXD(data) {
|
|
3774
|
+
super.add(protocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3543
3775
|
return this;
|
|
3544
3776
|
}
|
|
3545
3777
|
/**
|
|
3546
|
-
* Applies
|
|
3778
|
+
* Applies protocol fee to amountIn through Aqua protocol
|
|
3547
3779
|
**/
|
|
3548
|
-
|
|
3549
|
-
super.add(
|
|
3780
|
+
aquaProtocolFeeAmountInXD(data) {
|
|
3781
|
+
super.add(aquaProtocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3550
3782
|
return this;
|
|
3551
3783
|
}
|
|
3552
3784
|
/**
|
|
3553
|
-
* Applies protocol fee to
|
|
3785
|
+
* Applies protocol fee, fetched from external contract, to amountIn with direct transfer
|
|
3554
3786
|
**/
|
|
3555
|
-
|
|
3556
|
-
super.add(
|
|
3787
|
+
dynamicProtocolFeeAmountInXD(data) {
|
|
3788
|
+
super.add(dynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
|
|
3557
3789
|
return this;
|
|
3558
3790
|
}
|
|
3559
3791
|
/**
|
|
3560
|
-
* Applies protocol fee to
|
|
3792
|
+
* Applies protocol fee, fetched from external contract, to amountIn through Aqua protocol
|
|
3561
3793
|
**/
|
|
3562
|
-
|
|
3563
|
-
super.add(
|
|
3794
|
+
aquaDynamicProtocolFeeAmountInXD(data) {
|
|
3795
|
+
super.add(aquaDynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
|
|
3564
3796
|
return this;
|
|
3565
3797
|
}
|
|
3566
3798
|
/**
|
|
@@ -3723,23 +3955,12 @@ var Order = class Order {
|
|
|
3723
3955
|
|
|
3724
3956
|
//#endregion
|
|
3725
3957
|
//#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 {
|
|
3958
|
+
var AquaAMMStrategy = class {
|
|
3731
3959
|
feeBpsIn;
|
|
3732
|
-
deltas;
|
|
3733
3960
|
decayPeriod;
|
|
3734
3961
|
protocolFee;
|
|
3735
3962
|
salt;
|
|
3736
|
-
constructor(
|
|
3737
|
-
this.tokenA = tokenA;
|
|
3738
|
-
this.tokenB = tokenB;
|
|
3739
|
-
}
|
|
3740
|
-
static new(tokens) {
|
|
3741
|
-
return new AquaAMMStrategy(tokens.tokenA, tokens.tokenB);
|
|
3742
|
-
}
|
|
3963
|
+
constructor() {}
|
|
3743
3964
|
withProtocolFee(bps, receiver) {
|
|
3744
3965
|
this.protocolFee = {
|
|
3745
3966
|
bps,
|
|
@@ -3747,13 +3968,6 @@ var AquaAMMStrategy = class AquaAMMStrategy {
|
|
|
3747
3968
|
};
|
|
3748
3969
|
return this;
|
|
3749
3970
|
}
|
|
3750
|
-
withDeltas(a, b) {
|
|
3751
|
-
this.deltas = {
|
|
3752
|
-
a,
|
|
3753
|
-
b
|
|
3754
|
-
};
|
|
3755
|
-
return this;
|
|
3756
|
-
}
|
|
3757
3971
|
withDecayPeriod(decayPeriod) {
|
|
3758
3972
|
this.decayPeriod = decayPeriod;
|
|
3759
3973
|
return this;
|
|
@@ -3766,22 +3980,80 @@ var AquaAMMStrategy = class AquaAMMStrategy {
|
|
|
3766
3980
|
this.salt = salt$1;
|
|
3767
3981
|
return this;
|
|
3768
3982
|
}
|
|
3983
|
+
};
|
|
3984
|
+
|
|
3985
|
+
//#endregion
|
|
3986
|
+
//#region src/swap-vm/strategies/aqua-xyc-amm-strategy.ts
|
|
3987
|
+
var AquaXYCAmmStrategy = class AquaXYCAmmStrategy extends AquaAMMStrategy {
|
|
3988
|
+
constructor(xycConcentrateArgs) {
|
|
3989
|
+
super();
|
|
3990
|
+
this.xycConcentrateArgs = xycConcentrateArgs;
|
|
3991
|
+
}
|
|
3992
|
+
static new() {
|
|
3993
|
+
return new AquaXYCAmmStrategy();
|
|
3994
|
+
}
|
|
3995
|
+
static newConcentrate(prices) {
|
|
3996
|
+
if ("rawPriceMin" in prices && "rawPriceMax" in prices) {
|
|
3997
|
+
const args = ConcentrateGrowLiquidity2DArgs.fromRawPrices(prices.rawPriceMin, prices.rawPriceMax);
|
|
3998
|
+
return new AquaXYCAmmStrategy(args);
|
|
3999
|
+
}
|
|
4000
|
+
if ("sqrtPriceMin" in prices && "sqrtPriceMax" in prices) {
|
|
4001
|
+
const args = ConcentrateGrowLiquidity2DArgs.fromSqrtPrices(prices.sqrtPriceMin, prices.sqrtPriceMax);
|
|
4002
|
+
return new AquaXYCAmmStrategy(args);
|
|
4003
|
+
}
|
|
4004
|
+
throw new Error("unknown parameters for newXYCConcentrate");
|
|
4005
|
+
}
|
|
3769
4006
|
build() {
|
|
3770
4007
|
const builder = new AquaProgramBuilder();
|
|
3771
|
-
if (this.
|
|
3772
|
-
const data =
|
|
3773
|
-
builder.add(
|
|
4008
|
+
if (this.protocolFee) {
|
|
4009
|
+
const data = ProtocolFeeArgs.fromBps(this.protocolFee.bps, this.protocolFee.receiver);
|
|
4010
|
+
builder.add(aquaProtocolFeeAmountInXD.createIx(data));
|
|
3774
4011
|
}
|
|
4012
|
+
if (this.xycConcentrateArgs) builder.add(concentrateGrowLiquidity2D.createIx(this.xycConcentrateArgs));
|
|
3775
4013
|
if (this.decayPeriod) builder.decayXD({ decayPeriod: this.decayPeriod });
|
|
3776
4014
|
if (this.feeBpsIn) {
|
|
3777
4015
|
const data = FlatFeeArgs.fromBps(this.feeBpsIn);
|
|
3778
4016
|
builder.add(flatFeeAmountInXD.createIx(data));
|
|
3779
4017
|
}
|
|
4018
|
+
builder.xycSwapXD();
|
|
4019
|
+
if (this.salt) builder.salt({ salt: this.salt });
|
|
4020
|
+
return builder.build();
|
|
4021
|
+
}
|
|
4022
|
+
};
|
|
4023
|
+
|
|
4024
|
+
//#endregion
|
|
4025
|
+
//#region src/swap-vm/strategies/aqua-pegged-amm-strategy.ts
|
|
4026
|
+
var AquaPeggedAmmStrategy = class AquaPeggedAmmStrategy extends AquaAMMStrategy {
|
|
4027
|
+
constructor(tokenA, tokenB, linearWidth) {
|
|
4028
|
+
super();
|
|
4029
|
+
this.tokenA = tokenA;
|
|
4030
|
+
this.tokenB = tokenB;
|
|
4031
|
+
this.linearWidth = linearWidth;
|
|
4032
|
+
}
|
|
4033
|
+
static new(data) {
|
|
4034
|
+
return new AquaPeggedAmmStrategy(data.tokenA, data.tokenB, data.linearWidth);
|
|
4035
|
+
}
|
|
4036
|
+
build() {
|
|
4037
|
+
const builder = new AquaProgramBuilder();
|
|
3780
4038
|
if (this.protocolFee) {
|
|
3781
4039
|
const data = ProtocolFeeArgs.fromBps(this.protocolFee.bps, this.protocolFee.receiver);
|
|
3782
|
-
builder.add(
|
|
4040
|
+
builder.add(aquaProtocolFeeAmountInXD.createIx(data));
|
|
3783
4041
|
}
|
|
3784
|
-
builder.
|
|
4042
|
+
if (this.decayPeriod) builder.decayXD({ decayPeriod: this.decayPeriod });
|
|
4043
|
+
if (this.feeBpsIn) {
|
|
4044
|
+
const data = FlatFeeArgs.fromBps(this.feeBpsIn);
|
|
4045
|
+
builder.add(flatFeeAmountInXD.createIx(data));
|
|
4046
|
+
}
|
|
4047
|
+
const peggedArgs = PeggedSwapArgs.fromTokens({
|
|
4048
|
+
address: this.tokenA.address,
|
|
4049
|
+
decimals: this.tokenA.decimals,
|
|
4050
|
+
reserve: this.tokenA.reserve
|
|
4051
|
+
}, {
|
|
4052
|
+
address: this.tokenB.address,
|
|
4053
|
+
decimals: this.tokenB.decimals,
|
|
4054
|
+
reserve: this.tokenB.reserve
|
|
4055
|
+
}, this.linearWidth);
|
|
4056
|
+
builder.peggedSwapGrowPriceRange2D(peggedArgs);
|
|
3785
4057
|
if (this.salt) builder.salt({ salt: this.salt });
|
|
3786
4058
|
return builder.build();
|
|
3787
4059
|
}
|
|
@@ -3807,7 +4079,9 @@ Object.defineProperty(exports, 'Address', {
|
|
|
3807
4079
|
}
|
|
3808
4080
|
});
|
|
3809
4081
|
exports.AquaAMMStrategy = AquaAMMStrategy;
|
|
4082
|
+
exports.AquaPeggedAmmStrategy = AquaPeggedAmmStrategy;
|
|
3810
4083
|
exports.AquaProgramBuilder = AquaProgramBuilder;
|
|
4084
|
+
exports.AquaXYCAmmStrategy = AquaXYCAmmStrategy;
|
|
3811
4085
|
Object.defineProperty(exports, 'CallInfo', {
|
|
3812
4086
|
enumerable: true,
|
|
3813
4087
|
get: function () {
|