@1inch/swap-vm-sdk 0.1.1 → 0.1.2-rc.2
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 +614 -339
- package/dist/index.mjs +615 -342
- 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/index.js
CHANGED
|
@@ -31,6 +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 __1inch_byte_utils_dist_constants = __toESM(require("@1inch/byte-utils/dist/constants"));
|
|
34
35
|
|
|
35
36
|
//#region src/abi/SwapVM.abi.ts
|
|
36
37
|
const SWAP_VM_ABI = [
|
|
@@ -347,6 +348,11 @@ const SWAP_VM_ABI = [
|
|
|
347
348
|
name: "amount",
|
|
348
349
|
type: "uint256",
|
|
349
350
|
internalType: "uint256"
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
name: "amountNetPulled",
|
|
354
|
+
type: "uint256",
|
|
355
|
+
internalType: "uint256"
|
|
350
356
|
}
|
|
351
357
|
]
|
|
352
358
|
},
|
|
@@ -414,6 +420,89 @@ const SWAP_VM_ABI = [
|
|
|
414
420
|
internalType: "uint256"
|
|
415
421
|
}]
|
|
416
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
|
+
},
|
|
417
506
|
{
|
|
418
507
|
type: "error",
|
|
419
508
|
name: "SafeTransferFromFailed",
|
|
@@ -515,6 +604,11 @@ const SWAP_VM_ABI = [
|
|
|
515
604
|
internalType: "uint256"
|
|
516
605
|
}]
|
|
517
606
|
},
|
|
607
|
+
{
|
|
608
|
+
type: "error",
|
|
609
|
+
name: "TakerTraitsDeadlineExpired",
|
|
610
|
+
inputs: []
|
|
611
|
+
},
|
|
518
612
|
{
|
|
519
613
|
type: "error",
|
|
520
614
|
name: "UnexpectedLock",
|
|
@@ -907,7 +1001,7 @@ var TakerTraits = class TakerTraits {
|
|
|
907
1001
|
static IS_STRICT_THRESHOLD_BIT_FLAG = 4n;
|
|
908
1002
|
static IS_FIRST_TRANSFER_FROM_TAKER_BIT_FLAG = 5n;
|
|
909
1003
|
static USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG = 6n;
|
|
910
|
-
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) {
|
|
911
1005
|
this.exactIn = exactIn;
|
|
912
1006
|
this.shouldUnwrap = shouldUnwrap;
|
|
913
1007
|
this.preTransferInCallbackEnabled = preTransferInCallbackEnabled;
|
|
@@ -917,6 +1011,7 @@ var TakerTraits = class TakerTraits {
|
|
|
917
1011
|
this.useTransferFromAndAquaPush = useTransferFromAndAquaPush;
|
|
918
1012
|
this.threshold = threshold;
|
|
919
1013
|
this.customReceiver = customReceiver;
|
|
1014
|
+
this.deadline = deadline$1;
|
|
920
1015
|
this.preTransferInHookData = preTransferInHookData;
|
|
921
1016
|
this.postTransferInHookData = postTransferInHookData;
|
|
922
1017
|
this.preTransferOutHookData = preTransferOutHookData;
|
|
@@ -931,7 +1026,7 @@ var TakerTraits = class TakerTraits {
|
|
|
931
1026
|
* Provides default values for unspecified fields.
|
|
932
1027
|
*/
|
|
933
1028
|
static new(data = {}) {
|
|
934
|
-
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);
|
|
935
1030
|
}
|
|
936
1031
|
/**
|
|
937
1032
|
* Creates a default TakerTraits instance with standard settings.
|
|
@@ -951,6 +1046,7 @@ var TakerTraits = class TakerTraits {
|
|
|
951
1046
|
firstTransferFromTaker: false,
|
|
952
1047
|
useTransferFromAndAquaPush: true,
|
|
953
1048
|
threshold: 0n,
|
|
1049
|
+
deadline: 0n,
|
|
954
1050
|
customReceiver: __1inch_sdk_core.Address.ZERO_ADDRESS,
|
|
955
1051
|
preTransferInHookData: __1inch_sdk_core.HexString.EMPTY,
|
|
956
1052
|
postTransferInHookData: __1inch_sdk_core.HexString.EMPTY,
|
|
@@ -965,16 +1061,16 @@ var TakerTraits = class TakerTraits {
|
|
|
965
1061
|
/**
|
|
966
1062
|
* Decodes a packed TakerTraits from a hex string.
|
|
967
1063
|
* The packed format consists of:
|
|
968
|
-
* -
|
|
1064
|
+
* - 20 bytes: 10 uint16 offsets for data sections
|
|
969
1065
|
* - 2 bytes: uint16 flags
|
|
970
|
-
* - Variable: data sections (threshold, to, hook data, callback data, etc.)
|
|
1066
|
+
* - Variable: data sections (threshold, to, deadline, hook data, callback data, etc.)
|
|
971
1067
|
* - Variable: signature
|
|
972
1068
|
*/
|
|
973
1069
|
static decode(packed) {
|
|
974
1070
|
const iter = __1inch_byte_utils.BytesIter.BigInt(packed.toString());
|
|
975
|
-
const offsets = Array.from({ length:
|
|
1071
|
+
const offsets = Array.from({ length: 10 }, () => Number(iter.nextUint16())).reverse();
|
|
976
1072
|
const flags = new __1inch_byte_utils.BN(iter.nextUint16());
|
|
977
|
-
const dataStr = (0, __1inch_byte_utils.trim0x)(packed.toString()).slice(
|
|
1073
|
+
const dataStr = (0, __1inch_byte_utils.trim0x)(packed.toString()).slice(44);
|
|
978
1074
|
const sections = [];
|
|
979
1075
|
offsets.forEach((offset, i) => {
|
|
980
1076
|
const start = i === 0 ? 0 : offsets[i - 1];
|
|
@@ -982,7 +1078,7 @@ var TakerTraits = class TakerTraits {
|
|
|
982
1078
|
});
|
|
983
1079
|
const lastOffset = offsets[offsets.length - 1];
|
|
984
1080
|
const signature = dataStr.length > lastOffset * 2 ? dataStr.slice(lastOffset * 2) : "";
|
|
985
|
-
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;
|
|
986
1082
|
return TakerTraits.new({
|
|
987
1083
|
exactIn: Boolean(flags.getBit(TakerTraits.IS_EXACT_IN_BIT_FLAG)),
|
|
988
1084
|
shouldUnwrap: Boolean(flags.getBit(TakerTraits.SHOULD_UNWRAP_BIT_FLAG)),
|
|
@@ -993,6 +1089,7 @@ var TakerTraits = class TakerTraits {
|
|
|
993
1089
|
useTransferFromAndAquaPush: Boolean(flags.getBit(TakerTraits.USE_TRANSFER_FROM_AND_AQUA_PUSH_FLAG)),
|
|
994
1090
|
threshold: threshold ? BigInt((0, __1inch_byte_utils.add0x)(threshold)) : 0n,
|
|
995
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,
|
|
996
1093
|
preTransferInHookData: preTransferInHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(preTransferInHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
997
1094
|
postTransferInHookData: postTransferInHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(postTransferInHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
998
1095
|
preTransferOutHookData: preTransferOutHookData ? new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(preTransferOutHookData)) : __1inch_sdk_core.HexString.EMPTY,
|
|
@@ -1021,6 +1118,7 @@ var TakerTraits = class TakerTraits {
|
|
|
1021
1118
|
const dataFields = [
|
|
1022
1119
|
this.threshold > 0n ? new __1inch_sdk_core.HexString("0x" + this.threshold.toString(16).padStart(64, "0")) : __1inch_sdk_core.HexString.EMPTY,
|
|
1023
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,
|
|
1024
1122
|
this.preTransferInHookData,
|
|
1025
1123
|
this.postTransferInHookData,
|
|
1026
1124
|
this.preTransferOutHookData,
|
|
@@ -1471,7 +1569,7 @@ var OnlyTakerTokenSupplyShareGteArgsCoder = class {
|
|
|
1471
1569
|
|
|
1472
1570
|
//#endregion
|
|
1473
1571
|
//#region src/swap-vm/instructions/controls/only-taker-token-supply-share-gte-args.ts
|
|
1474
|
-
const UINT_64_MAX$
|
|
1572
|
+
const UINT_64_MAX$5 = 0xffffffffffffffffn;
|
|
1475
1573
|
/**
|
|
1476
1574
|
* Arguments for checking if taker holds at least specified share of token's total supply
|
|
1477
1575
|
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Controls.sol#L10
|
|
@@ -1481,7 +1579,7 @@ var OnlyTakerTokenSupplyShareGteArgs = class OnlyTakerTokenSupplyShareGteArgs {
|
|
|
1481
1579
|
constructor(token, minShareE18) {
|
|
1482
1580
|
this.token = token;
|
|
1483
1581
|
this.minShareE18 = minShareE18;
|
|
1484
|
-
(0, assert.default)(minShareE18 >= 0n && minShareE18 <= UINT_64_MAX$
|
|
1582
|
+
(0, assert.default)(minShareE18 >= 0n && minShareE18 <= UINT_64_MAX$5, `Invalid minShareE18 value: ${minShareE18}. Must be a valid uint64`);
|
|
1485
1583
|
}
|
|
1486
1584
|
/**
|
|
1487
1585
|
* Decodes hex data into OnlyTakerTokenSupplyShareGteArgs instance
|
|
@@ -1750,100 +1848,71 @@ __export(xyc_swap_exports, {
|
|
|
1750
1848
|
xycSwapXD: () => xycSwapXD
|
|
1751
1849
|
});
|
|
1752
1850
|
|
|
1753
|
-
//#endregion
|
|
1754
|
-
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args-coder.ts
|
|
1755
|
-
var ConcentrateGrowLiquidityXDArgsCoder = class {
|
|
1756
|
-
encode(args) {
|
|
1757
|
-
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1758
|
-
builder.addUint16(BigInt(args.tokenDeltas.length));
|
|
1759
|
-
for (const { tokenHalf } of args.tokenDeltas) builder.addBytes(tokenHalf.toString());
|
|
1760
|
-
for (const { delta } of args.tokenDeltas) builder.addUint256(delta);
|
|
1761
|
-
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
1762
|
-
}
|
|
1763
|
-
decode(data) {
|
|
1764
|
-
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
1765
|
-
const tokenCount = Number(iter.nextUint16());
|
|
1766
|
-
const tokenHalves = [];
|
|
1767
|
-
for (let i = 0; i < tokenCount; i++) {
|
|
1768
|
-
const bytes = iter.nextBytes(10);
|
|
1769
|
-
tokenHalves.push(__1inch_sdk_core.AddressHalf.fromHex(bytes));
|
|
1770
|
-
}
|
|
1771
|
-
const tokenDeltas = [];
|
|
1772
|
-
for (let i = 0; i < tokenCount; i++) tokenDeltas.push({
|
|
1773
|
-
tokenHalf: tokenHalves[i],
|
|
1774
|
-
delta: BigInt(iter.nextUint256())
|
|
1775
|
-
});
|
|
1776
|
-
return new ConcentrateGrowLiquidityXDArgs(tokenDeltas);
|
|
1777
|
-
}
|
|
1778
|
-
};
|
|
1779
|
-
|
|
1780
|
-
//#endregion
|
|
1781
|
-
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-xd-args.ts
|
|
1782
|
-
/**
|
|
1783
|
-
* Arguments for concentrateGrowLiquidityXD instruction with multiple token deltas
|
|
1784
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L139
|
|
1785
|
-
**/
|
|
1786
|
-
var ConcentrateGrowLiquidityXDArgs = class ConcentrateGrowLiquidityXDArgs {
|
|
1787
|
-
static CODER = new ConcentrateGrowLiquidityXDArgsCoder();
|
|
1788
|
-
constructor(tokenDeltas) {
|
|
1789
|
-
this.tokenDeltas = tokenDeltas;
|
|
1790
|
-
tokenDeltas.forEach((td, index) => {
|
|
1791
|
-
(0, 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`);
|
|
1792
|
-
});
|
|
1793
|
-
}
|
|
1794
|
-
/**
|
|
1795
|
-
* Decodes hex data into ConcentrateGrowLiquidityXDArgs instance
|
|
1796
|
-
**/
|
|
1797
|
-
static decode(data) {
|
|
1798
|
-
return ConcentrateGrowLiquidityXDArgs.CODER.decode(data);
|
|
1799
|
-
}
|
|
1800
|
-
toJSON() {
|
|
1801
|
-
return { tokenDeltas: this.tokenDeltas.map(({ tokenHalf, delta }) => ({
|
|
1802
|
-
token: tokenHalf.toString(),
|
|
1803
|
-
delta: delta.toString()
|
|
1804
|
-
})) };
|
|
1805
|
-
}
|
|
1806
|
-
};
|
|
1807
|
-
|
|
1808
1851
|
//#endregion
|
|
1809
1852
|
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args-coder.ts
|
|
1810
1853
|
var ConcentrateGrowLiquidity2DArgsCoder = class {
|
|
1811
1854
|
encode(args) {
|
|
1812
1855
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
1813
|
-
builder.addUint256(args.
|
|
1814
|
-
builder.addUint256(args.
|
|
1856
|
+
builder.addUint256(args.sqrtPriceMin);
|
|
1857
|
+
builder.addUint256(args.sqrtPriceMax);
|
|
1815
1858
|
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
1816
1859
|
}
|
|
1817
1860
|
decode(data) {
|
|
1818
1861
|
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
1819
|
-
const
|
|
1820
|
-
const
|
|
1821
|
-
return new ConcentrateGrowLiquidity2DArgs(
|
|
1862
|
+
const sqrtPriceMin = iter.nextUint256();
|
|
1863
|
+
const sqrtPriceMax = iter.nextUint256();
|
|
1864
|
+
return new ConcentrateGrowLiquidity2DArgs(sqrtPriceMin, sqrtPriceMax);
|
|
1822
1865
|
}
|
|
1823
1866
|
};
|
|
1824
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
|
+
|
|
1825
1883
|
//#endregion
|
|
1826
1884
|
//#region src/swap-vm/instructions/concentrate/concentrate-grow-liquidity-2d-args.ts
|
|
1885
|
+
const ONE_E18 = 10n ** 18n;
|
|
1827
1886
|
/**
|
|
1828
|
-
* 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
|
|
1829
1890
|
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
|
|
1830
1891
|
**/
|
|
1831
1892
|
var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
|
|
1832
1893
|
static CODER = new ConcentrateGrowLiquidity2DArgsCoder();
|
|
1833
|
-
constructor(
|
|
1834
|
-
this.
|
|
1835
|
-
this.
|
|
1836
|
-
(0, assert.default)(
|
|
1837
|
-
(0, assert.default)(
|
|
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);
|
|
1838
1907
|
}
|
|
1839
1908
|
/**
|
|
1840
|
-
*
|
|
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.
|
|
1841
1911
|
**/
|
|
1842
|
-
static
|
|
1843
|
-
const
|
|
1844
|
-
const
|
|
1845
|
-
|
|
1846
|
-
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);
|
|
1847
1916
|
}
|
|
1848
1917
|
/**
|
|
1849
1918
|
* Decodes hex data into ConcentrateGrowLiquidity2DArgs instance
|
|
@@ -1853,8 +1922,8 @@ var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
|
|
|
1853
1922
|
}
|
|
1854
1923
|
toJSON() {
|
|
1855
1924
|
return {
|
|
1856
|
-
|
|
1857
|
-
|
|
1925
|
+
sqrtPriceMin: this.sqrtPriceMin.toString(),
|
|
1926
|
+
sqrtPriceMax: this.sqrtPriceMax.toString()
|
|
1858
1927
|
};
|
|
1859
1928
|
}
|
|
1860
1929
|
};
|
|
@@ -1862,36 +1931,97 @@ var ConcentrateGrowLiquidity2DArgs = class ConcentrateGrowLiquidity2DArgs {
|
|
|
1862
1931
|
//#endregion
|
|
1863
1932
|
//#region src/swap-vm/instructions/concentrate/opcodes.ts
|
|
1864
1933
|
/**
|
|
1865
|
-
* Concentrates liquidity within price bounds for multiple tokens
|
|
1866
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L139
|
|
1867
|
-
**/
|
|
1868
|
-
const concentrateGrowLiquidityXD = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidityXD"), ConcentrateGrowLiquidityXDArgs.CODER);
|
|
1869
|
-
/**
|
|
1870
1934
|
* Concentrates liquidity within price bounds for two tokens
|
|
1871
1935
|
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/XYCConcentrate.sol#L172
|
|
1872
1936
|
**/
|
|
1873
1937
|
const concentrateGrowLiquidity2D = new Opcode(Symbol("XYCConcentrate.concentrateGrowLiquidity2D"), ConcentrateGrowLiquidity2DArgs.CODER);
|
|
1874
1938
|
|
|
1875
1939
|
//#endregion
|
|
1876
|
-
//#region src/swap-vm/instructions/concentrate/
|
|
1877
|
-
const
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
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);
|
|
1881
1962
|
return {
|
|
1882
|
-
|
|
1883
|
-
|
|
1963
|
+
targetL,
|
|
1964
|
+
actualLt,
|
|
1965
|
+
actualGt
|
|
1884
1966
|
};
|
|
1885
1967
|
}
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
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;
|
|
1895
2025
|
}
|
|
1896
2026
|
|
|
1897
2027
|
//#endregion
|
|
@@ -1899,10 +2029,12 @@ function sqrt(value) {
|
|
|
1899
2029
|
var concentrate_exports = {};
|
|
1900
2030
|
__export(concentrate_exports, {
|
|
1901
2031
|
ConcentrateGrowLiquidity2DArgs: () => ConcentrateGrowLiquidity2DArgs,
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2032
|
+
ONE_E18: () => ONE_E18,
|
|
2033
|
+
bigintSqrt: () => bigintSqrt,
|
|
2034
|
+
computeBalances: () => computeBalances,
|
|
2035
|
+
computeLiquidityAndPrice: () => computeLiquidityAndPrice,
|
|
2036
|
+
computeLiquidityFromAmounts: () => computeLiquidityFromAmounts,
|
|
2037
|
+
concentrateGrowLiquidity2D: () => concentrateGrowLiquidity2D
|
|
1906
2038
|
});
|
|
1907
2039
|
|
|
1908
2040
|
//#endregion
|
|
@@ -2103,14 +2235,14 @@ var DutchAuctionArgsCoder = class {
|
|
|
2103
2235
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2104
2236
|
builder.addUint40(args.startTime);
|
|
2105
2237
|
builder.addUint16(args.duration);
|
|
2106
|
-
builder.
|
|
2238
|
+
builder.addUint64(args.decayFactor);
|
|
2107
2239
|
return new __1inch_sdk_core.HexString((0, __1inch_byte_utils.add0x)(builder.asHex()));
|
|
2108
2240
|
}
|
|
2109
2241
|
decode(data) {
|
|
2110
2242
|
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2111
2243
|
const startTime = iter.nextUint40();
|
|
2112
2244
|
const duration = iter.nextUint16();
|
|
2113
|
-
const decayFactor = iter.
|
|
2245
|
+
const decayFactor = iter.nextUint64();
|
|
2114
2246
|
return new DutchAuctionArgs(startTime, duration, decayFactor);
|
|
2115
2247
|
}
|
|
2116
2248
|
};
|
|
@@ -2128,7 +2260,6 @@ var DutchAuctionArgsCoder = class {
|
|
|
2128
2260
|
* - Only works for 1=>0 swaps (token1 to token0)
|
|
2129
2261
|
*
|
|
2130
2262
|
* The decay factor determines the price reduction rate:
|
|
2131
|
-
* - 1.0e18 = no decay (constant price)
|
|
2132
2263
|
* - 0.999e18 = 0.1% decay per second
|
|
2133
2264
|
* - 0.99e18 = 1% decay per second
|
|
2134
2265
|
* - 0.9e18 = 10% decay per second
|
|
@@ -2147,7 +2278,7 @@ var DutchAuctionArgs = class DutchAuctionArgs {
|
|
|
2147
2278
|
/**
|
|
2148
2279
|
* startTime - auction start time (uint40)
|
|
2149
2280
|
* duration - auction duration in seconds (uint16)
|
|
2150
|
-
* decayFactor - price decay per second, 1e18 = no decay (
|
|
2281
|
+
* decayFactor - price decay per second, 1e18 = no decay (uint64)
|
|
2151
2282
|
**/
|
|
2152
2283
|
constructor(startTime, duration, decayFactor) {
|
|
2153
2284
|
this.startTime = startTime;
|
|
@@ -2155,7 +2286,7 @@ var DutchAuctionArgs = class DutchAuctionArgs {
|
|
|
2155
2286
|
this.decayFactor = decayFactor;
|
|
2156
2287
|
(0, assert.default)(startTime >= 0n && startTime <= __1inch_byte_utils.UINT_40_MAX, `Invalid startTime: ${startTime}. Must be a valid uint40`);
|
|
2157
2288
|
(0, assert.default)(duration >= 0n && duration <= __1inch_byte_utils.UINT_16_MAX, `Invalid duration: ${duration}. Must be a valid uint16`);
|
|
2158
|
-
(0, assert.default)(decayFactor >= 0n && decayFactor <=
|
|
2289
|
+
(0, assert.default)(decayFactor >= 0n && decayFactor <= __1inch_byte_utils_dist_constants.UINT_64_MAX, `Invalid decayFactor: ${decayFactor}. Must be a valid uint64`);
|
|
2159
2290
|
(0, assert.default)(decayFactor < 1e18, `Decay factor should be less than 1e18: ${decayFactor}`);
|
|
2160
2291
|
}
|
|
2161
2292
|
/**
|
|
@@ -2195,99 +2326,6 @@ __export(dutch_auction_exports, {
|
|
|
2195
2326
|
dutchAuctionBalanceOut1D: () => dutchAuctionBalanceOut1D
|
|
2196
2327
|
});
|
|
2197
2328
|
|
|
2198
|
-
//#endregion
|
|
2199
|
-
//#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args-coder.ts
|
|
2200
|
-
var OraclePriceAdjusterArgsCoder = class {
|
|
2201
|
-
encode(args) {
|
|
2202
|
-
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2203
|
-
builder.addUint64(args.maxPriceDecay);
|
|
2204
|
-
builder.addUint16(args.maxStaleness);
|
|
2205
|
-
builder.addUint8(args.oracleDecimals);
|
|
2206
|
-
builder.addAddress(args.oracleAddress.toString());
|
|
2207
|
-
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
2208
|
-
}
|
|
2209
|
-
decode(data) {
|
|
2210
|
-
const iter = __1inch_byte_utils.BytesIter.HexString(data.toString());
|
|
2211
|
-
const maxPriceDecay = iter.nextUint64();
|
|
2212
|
-
const maxStaleness = iter.nextUint16();
|
|
2213
|
-
const oracleDecimals = iter.nextUint8();
|
|
2214
|
-
const oracleAddress = new __1inch_sdk_core.Address(iter.nextAddress());
|
|
2215
|
-
return new OraclePriceAdjusterArgs(BigInt(maxPriceDecay), BigInt(maxStaleness), BigInt(oracleDecimals), oracleAddress);
|
|
2216
|
-
}
|
|
2217
|
-
};
|
|
2218
|
-
|
|
2219
|
-
//#endregion
|
|
2220
|
-
//#region src/swap-vm/instructions/oracle-price-adjuster/oracle-price-adjuster-args.ts
|
|
2221
|
-
/**
|
|
2222
|
-
* @notice Oracle Price Adjuster instruction for dynamic price adjustment based on Chainlink price feeds
|
|
2223
|
-
* @dev Adjusts swap prices to match Chainlink oracle prices within safe bounds:
|
|
2224
|
-
* - Works only for 1=>0 swaps (token1 to token0), compatible with LimitSwap and other swap instructions
|
|
2225
|
-
* - Fetches current market price from a Chainlink oracle (AggregatorV3Interface)
|
|
2226
|
-
* - Adjusts the swap price towards the oracle price within maxPriceDecay limits
|
|
2227
|
-
* - Ensures the adjustment is always favorable for the taker
|
|
2228
|
-
* - Handles different decimal places from Chainlink oracles (e.g., 8 decimals for USD prices)
|
|
2229
|
-
*
|
|
2230
|
-
* This creates adaptive orders that automatically track market prices while maintaining
|
|
2231
|
-
* safety bounds to prevent excessive slippage or manipulation.
|
|
2232
|
-
*
|
|
2233
|
-
* Example usage:
|
|
2234
|
-
* 1. LimitSwap sets base price: 1 ETH for 3000 USDC
|
|
2235
|
-
* 2. OraclePriceAdjuster with Chainlink ETH/USD oracle: 1 ETH = 3100 USD, maxPriceDecay=0.95e18 (5% max)
|
|
2236
|
-
* 3. exactIn: Taker gets more ETH (up to 5% improvement)
|
|
2237
|
-
* 4. exactOut: Taker pays less USDC (up to 5% discount)
|
|
2238
|
-
*
|
|
2239
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
|
|
2240
|
-
*/
|
|
2241
|
-
var OraclePriceAdjusterArgs = class OraclePriceAdjusterArgs {
|
|
2242
|
-
static CODER = new OraclePriceAdjusterArgsCoder();
|
|
2243
|
-
/**
|
|
2244
|
-
* maxPriceDecay - maximum price decay coefficient (uint64)
|
|
2245
|
-
* maxStaleness - maximum allowed oracle data staleness in seconds (uint16
|
|
2246
|
-
* oracleDecimals - decimals used by the oracle (uint8)
|
|
2247
|
-
* oracleAddress - address of the Chainlink price oracle contract
|
|
2248
|
-
**/
|
|
2249
|
-
constructor(maxPriceDecay, maxStaleness, oracleDecimals, oracleAddress) {
|
|
2250
|
-
this.maxPriceDecay = maxPriceDecay;
|
|
2251
|
-
this.maxStaleness = maxStaleness;
|
|
2252
|
-
this.oracleDecimals = oracleDecimals;
|
|
2253
|
-
this.oracleAddress = oracleAddress;
|
|
2254
|
-
(0, assert.default)(maxPriceDecay >= 0n && maxPriceDecay <= __1inch_byte_utils.UINT_64_MAX, `Invalid maxPriceDecay: ${maxPriceDecay}. Must be a valid uint64`);
|
|
2255
|
-
(0, assert.default)(maxPriceDecay < 1e18, `Max price decay should be less than 1e18: ${maxPriceDecay}`);
|
|
2256
|
-
(0, assert.default)(maxStaleness >= 0n && maxStaleness <= __1inch_byte_utils.UINT_16_MAX, `Invalid maxStaleness: ${maxStaleness}. Must be a valid uint16`);
|
|
2257
|
-
(0, assert.default)(oracleDecimals >= 0n && oracleDecimals <= __1inch_byte_utils.UINT_8_MAX, `Invalid oracleDecimals: ${oracleDecimals}. Must be a valid uint8`);
|
|
2258
|
-
}
|
|
2259
|
-
/**
|
|
2260
|
-
* Decodes hex data into OraclePriceAdjusterArgs instance
|
|
2261
|
-
**/
|
|
2262
|
-
static decode(data) {
|
|
2263
|
-
return OraclePriceAdjusterArgs.CODER.decode(data);
|
|
2264
|
-
}
|
|
2265
|
-
toJSON() {
|
|
2266
|
-
return {
|
|
2267
|
-
maxPriceDecay: this.maxPriceDecay.toString(),
|
|
2268
|
-
maxStaleness: this.maxStaleness.toString(),
|
|
2269
|
-
oracleDecimals: this.oracleDecimals.toString(),
|
|
2270
|
-
oracleAddress: this.oracleAddress.toString()
|
|
2271
|
-
};
|
|
2272
|
-
}
|
|
2273
|
-
};
|
|
2274
|
-
|
|
2275
|
-
//#endregion
|
|
2276
|
-
//#region src/swap-vm/instructions/oracle-price-adjuster/opcodes.ts
|
|
2277
|
-
/**
|
|
2278
|
-
* Adjusts swap prices based on Chainlink oracle feeds
|
|
2279
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
|
|
2280
|
-
**/
|
|
2281
|
-
const oraclePriceAdjuster1D = new Opcode(Symbol("OraclePriceAdjuster.oraclePriceAdjuster1D"), OraclePriceAdjusterArgs.CODER);
|
|
2282
|
-
|
|
2283
|
-
//#endregion
|
|
2284
|
-
//#region src/swap-vm/instructions/oracle-price-adjuster/index.ts
|
|
2285
|
-
var oracle_price_adjuster_exports = {};
|
|
2286
|
-
__export(oracle_price_adjuster_exports, {
|
|
2287
|
-
OraclePriceAdjusterArgs: () => OraclePriceAdjusterArgs,
|
|
2288
|
-
oraclePriceAdjuster1D: () => oraclePriceAdjuster1D
|
|
2289
|
-
});
|
|
2290
|
-
|
|
2291
2329
|
//#endregion
|
|
2292
2330
|
//#region src/swap-vm/instructions/base-fee-adjuster/base-fee-adjuster-args-coder.ts
|
|
2293
2331
|
var BaseFeeAdjusterArgsCoder = class {
|
|
@@ -2512,7 +2550,7 @@ __export(twap_swap_exports, {
|
|
|
2512
2550
|
});
|
|
2513
2551
|
|
|
2514
2552
|
//#endregion
|
|
2515
|
-
//#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
|
|
2516
2554
|
var FlatFeeArgsCoder = class {
|
|
2517
2555
|
encode(args) {
|
|
2518
2556
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
@@ -2527,10 +2565,10 @@ var FlatFeeArgsCoder = class {
|
|
|
2527
2565
|
};
|
|
2528
2566
|
|
|
2529
2567
|
//#endregion
|
|
2530
|
-
//#region src/swap-vm/instructions/fee/flat-fee-args.ts
|
|
2568
|
+
//#region src/swap-vm/instructions/fee/flat-fee/flat-fee-args.ts
|
|
2531
2569
|
const FEE_100_PERCENT$1 = 1e9;
|
|
2532
2570
|
/**
|
|
2533
|
-
* Arguments for flat fee instructions (
|
|
2571
|
+
* Arguments for flat fee instructions (flatFeeAmountInXD)
|
|
2534
2572
|
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/Fee.sol#L66
|
|
2535
2573
|
**/
|
|
2536
2574
|
var FlatFeeArgs = class FlatFeeArgs {
|
|
@@ -2569,7 +2607,7 @@ var FlatFeeArgs = class FlatFeeArgs {
|
|
|
2569
2607
|
};
|
|
2570
2608
|
|
|
2571
2609
|
//#endregion
|
|
2572
|
-
//#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
|
|
2573
2611
|
var ProtocolFeeArgsCoder = class {
|
|
2574
2612
|
encode(args) {
|
|
2575
2613
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
@@ -2586,11 +2624,11 @@ var ProtocolFeeArgsCoder = class {
|
|
|
2586
2624
|
};
|
|
2587
2625
|
|
|
2588
2626
|
//#endregion
|
|
2589
|
-
//#region src/swap-vm/instructions/fee/protocol-fee-args.ts
|
|
2627
|
+
//#region src/swap-vm/instructions/fee/protocol-fee/protocol-fee-args.ts
|
|
2590
2628
|
const FEE_100_PERCENT = 1e9;
|
|
2591
2629
|
/**
|
|
2592
|
-
* Arguments for protocol fee instructions (
|
|
2593
|
-
* @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
|
|
2594
2632
|
**/
|
|
2595
2633
|
var ProtocolFeeArgs = class ProtocolFeeArgs {
|
|
2596
2634
|
static CODER = new ProtocolFeeArgsCoder();
|
|
@@ -2637,50 +2675,110 @@ var ProtocolFeeArgs = class ProtocolFeeArgs {
|
|
|
2637
2675
|
}
|
|
2638
2676
|
};
|
|
2639
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
|
+
|
|
2640
2713
|
//#endregion
|
|
2641
2714
|
//#region src/swap-vm/instructions/fee/opcodes.ts
|
|
2642
2715
|
/**
|
|
2643
2716
|
* Applies fee to amountIn
|
|
2644
|
-
* @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
|
|
2645
2718
|
**/
|
|
2646
2719
|
const flatFeeAmountInXD = new Opcode(Symbol("Fee.flatFeeAmountInXD"), FlatFeeArgs.CODER);
|
|
2647
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
|
+
/**
|
|
2648
2741
|
* Applies fee to amountOut
|
|
2649
|
-
* @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
|
|
2650
2743
|
**/
|
|
2651
|
-
const flatFeeAmountOutXD = new Opcode(Symbol("
|
|
2744
|
+
const flatFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.flatFeeAmountOutXD"), FlatFeeArgs.CODER);
|
|
2652
2745
|
/**
|
|
2653
2746
|
* Applies progressive fee to amountIn
|
|
2654
|
-
* @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
|
|
2655
2748
|
**/
|
|
2656
|
-
const progressiveFeeInXD = new Opcode(Symbol("
|
|
2749
|
+
const progressiveFeeInXD = new Opcode(Symbol("FeeExperimental.progressiveFeeInXD"), FlatFeeArgs.CODER);
|
|
2657
2750
|
/**
|
|
2658
2751
|
* Applies progressive fee to amountOut
|
|
2659
|
-
* @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
|
|
2660
2753
|
**/
|
|
2661
|
-
const progressiveFeeOutXD = new Opcode(Symbol("
|
|
2754
|
+
const progressiveFeeOutXD = new Opcode(Symbol("FeeExperimental.progressiveFeeOutXD"), FlatFeeArgs.CODER);
|
|
2662
2755
|
/**
|
|
2663
|
-
*
|
|
2664
|
-
* @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
|
|
2665
2758
|
**/
|
|
2666
|
-
const protocolFeeAmountOutXD = new Opcode(Symbol("
|
|
2759
|
+
const protocolFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.protocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
|
|
2667
2760
|
/**
|
|
2668
|
-
*
|
|
2669
|
-
* @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
|
|
2670
2763
|
**/
|
|
2671
|
-
const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("
|
|
2764
|
+
const aquaProtocolFeeAmountOutXD = new Opcode(Symbol("FeeExperimental.aquaProtocolFeeAmountOutXD"), ProtocolFeeArgs.CODER);
|
|
2672
2765
|
|
|
2673
2766
|
//#endregion
|
|
2674
2767
|
//#region src/swap-vm/instructions/fee/index.ts
|
|
2675
2768
|
var fee_exports = {};
|
|
2676
2769
|
__export(fee_exports, {
|
|
2770
|
+
DynamicProtocolFeeArgs: () => DynamicProtocolFeeArgs,
|
|
2677
2771
|
FlatFeeArgs: () => FlatFeeArgs,
|
|
2678
2772
|
ProtocolFeeArgs: () => ProtocolFeeArgs,
|
|
2773
|
+
aquaDynamicProtocolFeeAmountInXD: () => aquaDynamicProtocolFeeAmountInXD,
|
|
2774
|
+
aquaProtocolFeeAmountInXD: () => aquaProtocolFeeAmountInXD,
|
|
2679
2775
|
aquaProtocolFeeAmountOutXD: () => aquaProtocolFeeAmountOutXD,
|
|
2776
|
+
dynamicProtocolFeeAmountInXD: () => dynamicProtocolFeeAmountInXD,
|
|
2680
2777
|
flatFeeAmountInXD: () => flatFeeAmountInXD,
|
|
2681
2778
|
flatFeeAmountOutXD: () => flatFeeAmountOutXD,
|
|
2682
2779
|
progressiveFeeInXD: () => progressiveFeeInXD,
|
|
2683
2780
|
progressiveFeeOutXD: () => progressiveFeeOutXD,
|
|
2781
|
+
protocolFeeAmountInXD: () => protocolFeeAmountInXD,
|
|
2684
2782
|
protocolFeeAmountOutXD: () => protocolFeeAmountOutXD
|
|
2685
2783
|
});
|
|
2686
2784
|
|
|
@@ -2748,63 +2846,81 @@ __export(extruction_exports, {
|
|
|
2748
2846
|
});
|
|
2749
2847
|
|
|
2750
2848
|
//#endregion
|
|
2751
|
-
//#region src/swap-vm/instructions/
|
|
2752
|
-
var
|
|
2849
|
+
//#region src/swap-vm/instructions/pegged-swap/pegged-swap-args-coder.ts
|
|
2850
|
+
var PeggedSwapArgsCoder = class {
|
|
2753
2851
|
encode(args) {
|
|
2754
2852
|
const builder = new __1inch_byte_utils.BytesBuilder();
|
|
2755
|
-
builder.
|
|
2756
|
-
builder.
|
|
2853
|
+
builder.addUint256(args.x0);
|
|
2854
|
+
builder.addUint256(args.y0);
|
|
2855
|
+
builder.addUint256(args.linearWidth);
|
|
2757
2856
|
builder.addUint256(args.rateLt);
|
|
2758
2857
|
builder.addUint256(args.rateGt);
|
|
2759
|
-
return new __1inch_sdk_core.HexString(
|
|
2858
|
+
return new __1inch_sdk_core.HexString(builder.asHex());
|
|
2760
2859
|
}
|
|
2761
2860
|
decode(data) {
|
|
2762
2861
|
const iter = __1inch_byte_utils.BytesIter.BigInt(data.toString());
|
|
2763
|
-
const
|
|
2764
|
-
const
|
|
2765
|
-
const
|
|
2766
|
-
const
|
|
2767
|
-
|
|
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);
|
|
2768
2868
|
}
|
|
2769
2869
|
};
|
|
2770
2870
|
|
|
2771
2871
|
//#endregion
|
|
2772
|
-
//#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
|
|
2773
2881
|
/**
|
|
2774
|
-
* 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
|
|
2775
2885
|
**/
|
|
2776
|
-
var
|
|
2777
|
-
static CODER = new
|
|
2886
|
+
var PeggedSwapArgs = class PeggedSwapArgs {
|
|
2887
|
+
static CODER = new PeggedSwapArgsCoder();
|
|
2778
2888
|
/**
|
|
2779
|
-
*
|
|
2780
|
-
*
|
|
2781
|
-
*
|
|
2782
|
-
*
|
|
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)
|
|
2783
2896
|
**/
|
|
2784
|
-
constructor(
|
|
2785
|
-
this.
|
|
2786
|
-
this.
|
|
2897
|
+
constructor(x0, y0, linearWidth, rateLt, rateGt) {
|
|
2898
|
+
this.x0 = x0;
|
|
2899
|
+
this.y0 = y0;
|
|
2900
|
+
this.linearWidth = linearWidth;
|
|
2787
2901
|
this.rateLt = rateLt;
|
|
2788
2902
|
this.rateGt = rateGt;
|
|
2789
|
-
(0, assert.default)(
|
|
2790
|
-
(0, assert.default)(
|
|
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}`);
|
|
2791
2907
|
(0, assert.default)(rateLt > 0n && rateLt <= __1inch_byte_utils.UINT_256_MAX, `Invalid rateLt: ${rateLt}. Must be positive and <= UINT_256_MAX`);
|
|
2792
2908
|
(0, assert.default)(rateGt > 0n && rateGt <= __1inch_byte_utils.UINT_256_MAX, `Invalid rateGt: ${rateGt}. Must be positive and <= UINT_256_MAX`);
|
|
2793
2909
|
}
|
|
2794
|
-
static fromTokens(
|
|
2795
|
-
|
|
2796
|
-
|
|
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);
|
|
2797
2915
|
}
|
|
2798
|
-
/**
|
|
2799
|
-
* Decodes hex data into StableSwap2DArgs instance
|
|
2800
|
-
**/
|
|
2801
2916
|
static decode(data) {
|
|
2802
|
-
return
|
|
2917
|
+
return PeggedSwapArgs.CODER.decode(data);
|
|
2803
2918
|
}
|
|
2804
2919
|
toJSON() {
|
|
2805
2920
|
return {
|
|
2806
|
-
|
|
2807
|
-
|
|
2921
|
+
x0: this.x0.toString(),
|
|
2922
|
+
y0: this.y0.toString(),
|
|
2923
|
+
linearWidth: this.linearWidth.toString(),
|
|
2808
2924
|
rateLt: this.rateLt.toString(),
|
|
2809
2925
|
rateGt: this.rateGt.toString()
|
|
2810
2926
|
};
|
|
@@ -2812,18 +2928,112 @@ var StableSwap2DArgs = class StableSwap2DArgs {
|
|
|
2812
2928
|
};
|
|
2813
2929
|
|
|
2814
2930
|
//#endregion
|
|
2815
|
-
//#region src/swap-vm/instructions/
|
|
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`);
|
|
3006
|
+
}
|
|
3007
|
+
/**
|
|
3008
|
+
* Decodes hex data into OraclePriceAdjusterArgs instance
|
|
3009
|
+
**/
|
|
3010
|
+
static decode(data) {
|
|
3011
|
+
return OraclePriceAdjusterArgs.CODER.decode(data);
|
|
3012
|
+
}
|
|
3013
|
+
toJSON() {
|
|
3014
|
+
return {
|
|
3015
|
+
maxPriceDecay: this.maxPriceDecay.toString(),
|
|
3016
|
+
maxStaleness: this.maxStaleness.toString(),
|
|
3017
|
+
oracleDecimals: this.oracleDecimals.toString(),
|
|
3018
|
+
oracleAddress: this.oracleAddress.toString()
|
|
3019
|
+
};
|
|
3020
|
+
}
|
|
3021
|
+
};
|
|
3022
|
+
|
|
3023
|
+
//#endregion
|
|
3024
|
+
//#region src/swap-vm/instructions/oracle-price-adjuster/opcodes.ts
|
|
2816
3025
|
/**
|
|
2817
|
-
*
|
|
3026
|
+
* Adjusts swap prices based on Chainlink oracle feeds
|
|
3027
|
+
* @see https://github.com/1inch/swap-vm/blob/main/src/instructions/OraclePriceAdjuster.sol#L84
|
|
2818
3028
|
**/
|
|
2819
|
-
const
|
|
3029
|
+
const oraclePriceAdjuster1D = new Opcode(Symbol("OraclePriceAdjuster.oraclePriceAdjuster1D"), OraclePriceAdjusterArgs.CODER);
|
|
2820
3030
|
|
|
2821
3031
|
//#endregion
|
|
2822
|
-
//#region src/swap-vm/instructions/
|
|
2823
|
-
var
|
|
2824
|
-
__export(
|
|
2825
|
-
|
|
2826
|
-
|
|
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
|
|
2827
3037
|
});
|
|
2828
3038
|
|
|
2829
3039
|
//#endregion
|
|
@@ -2845,7 +3055,8 @@ __export(instructions_exports, {
|
|
|
2845
3055
|
limitSwap: () => limit_swap_exports,
|
|
2846
3056
|
minRate: () => min_rate_exports,
|
|
2847
3057
|
oraclePriceAdjuster: () => oracle_price_adjuster_exports,
|
|
2848
|
-
|
|
3058
|
+
peggedSwap: () => pegged_swap_exports,
|
|
3059
|
+
stableSwap: () => pegged_swap_exports,
|
|
2849
3060
|
twapSwap: () => twap_swap_exports,
|
|
2850
3061
|
xycSwap: () => xyc_swap_exports
|
|
2851
3062
|
});
|
|
@@ -2877,7 +3088,6 @@ const _allInstructions = [
|
|
|
2877
3088
|
invalidateTokenIn1D,
|
|
2878
3089
|
invalidateTokenOut1D,
|
|
2879
3090
|
xycSwapXD,
|
|
2880
|
-
concentrateGrowLiquidityXD,
|
|
2881
3091
|
concentrateGrowLiquidity2D,
|
|
2882
3092
|
decayXD,
|
|
2883
3093
|
limitSwap1D,
|
|
@@ -2886,7 +3096,6 @@ const _allInstructions = [
|
|
|
2886
3096
|
adjustMinRate1D,
|
|
2887
3097
|
dutchAuctionBalanceIn1D,
|
|
2888
3098
|
dutchAuctionBalanceOut1D,
|
|
2889
|
-
oraclePriceAdjuster1D,
|
|
2890
3099
|
baseFeeAdjuster1D,
|
|
2891
3100
|
twap,
|
|
2892
3101
|
extruction,
|
|
@@ -2896,7 +3105,12 @@ const _allInstructions = [
|
|
|
2896
3105
|
progressiveFeeInXD,
|
|
2897
3106
|
progressiveFeeOutXD,
|
|
2898
3107
|
protocolFeeAmountOutXD,
|
|
2899
|
-
aquaProtocolFeeAmountOutXD
|
|
3108
|
+
aquaProtocolFeeAmountOutXD,
|
|
3109
|
+
peggedSwapGrowPriceRange2D,
|
|
3110
|
+
protocolFeeAmountInXD,
|
|
3111
|
+
aquaProtocolFeeAmountInXD,
|
|
3112
|
+
dynamicProtocolFeeAmountInXD,
|
|
3113
|
+
aquaDynamicProtocolFeeAmountInXD
|
|
2900
3114
|
];
|
|
2901
3115
|
/**
|
|
2902
3116
|
* Aqua opcodes array - matching AquaSwapVM contract (29 opcodes)
|
|
@@ -2921,16 +3135,21 @@ const aquaInstructions = [
|
|
|
2921
3135
|
onlyTakerTokenBalanceGte,
|
|
2922
3136
|
onlyTakerTokenSupplyShareGte,
|
|
2923
3137
|
xycSwapXD,
|
|
2924
|
-
concentrateGrowLiquidityXD,
|
|
2925
3138
|
concentrateGrowLiquidity2D,
|
|
2926
3139
|
decayXD,
|
|
2927
3140
|
salt,
|
|
2928
3141
|
flatFeeAmountInXD,
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
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
|
|
2934
3153
|
];
|
|
2935
3154
|
|
|
2936
3155
|
//#endregion
|
|
@@ -3232,17 +3451,17 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3232
3451
|
return this;
|
|
3233
3452
|
}
|
|
3234
3453
|
/**
|
|
3235
|
-
* Concentrates liquidity within price bounds for
|
|
3454
|
+
* Concentrates liquidity within price bounds for two tokens
|
|
3236
3455
|
**/
|
|
3237
|
-
|
|
3238
|
-
super.add(
|
|
3456
|
+
concentrateGrowLiquidity2D(data) {
|
|
3457
|
+
super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.sqrtPriceMin, data.sqrtPriceMax)));
|
|
3239
3458
|
return this;
|
|
3240
3459
|
}
|
|
3241
3460
|
/**
|
|
3242
|
-
*
|
|
3461
|
+
* Square-root linear swap curve for pegged assets
|
|
3243
3462
|
**/
|
|
3244
|
-
|
|
3245
|
-
super.add(
|
|
3463
|
+
peggedSwapGrowPriceRange2D(data) {
|
|
3464
|
+
super.add(peggedSwapGrowPriceRange2D.createIx(new PeggedSwapArgs(data.x0, data.y0, data.linearWidth, data.rateLt, data.rateGt)));
|
|
3246
3465
|
return this;
|
|
3247
3466
|
}
|
|
3248
3467
|
/**
|
|
@@ -3295,13 +3514,6 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3295
3514
|
return this;
|
|
3296
3515
|
}
|
|
3297
3516
|
/**
|
|
3298
|
-
* Adjusts swap prices based on Chainlink oracle feeds
|
|
3299
|
-
**/
|
|
3300
|
-
oraclePriceAdjuster1D(data) {
|
|
3301
|
-
super.add(oraclePriceAdjuster1D.createIx(new OraclePriceAdjusterArgs(data.maxPriceDecay, data.maxStaleness, data.oracleDecimals, data.oracleAddress)));
|
|
3302
|
-
return this;
|
|
3303
|
-
}
|
|
3304
|
-
/**
|
|
3305
3517
|
* Adjusts swap prices based on network gas costs
|
|
3306
3518
|
**/
|
|
3307
3519
|
baseFeeAdjuster1D(data) {
|
|
@@ -3351,6 +3563,13 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3351
3563
|
return this;
|
|
3352
3564
|
}
|
|
3353
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
|
+
/**
|
|
3354
3573
|
* Applies protocol fee to amountOut with direct transfer
|
|
3355
3574
|
**/
|
|
3356
3575
|
protocolFeeAmountOutXD(data) {
|
|
@@ -3358,6 +3577,13 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3358
3577
|
return this;
|
|
3359
3578
|
}
|
|
3360
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
|
+
/**
|
|
3361
3587
|
* Applies protocol fee to amountOut through Aqua protocol
|
|
3362
3588
|
**/
|
|
3363
3589
|
aquaProtocolFeeAmountOutXD(data) {
|
|
@@ -3365,6 +3591,20 @@ var RegularProgramBuilder = class RegularProgramBuilder extends ProgramBuilder {
|
|
|
3365
3591
|
return this;
|
|
3366
3592
|
}
|
|
3367
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
|
+
/**
|
|
3368
3608
|
* DEBUG: Prints current swap registers (amounts and tokens)
|
|
3369
3609
|
* WARNING: Requires withDebug() to be called first, otherwise will throw an error
|
|
3370
3610
|
*/
|
|
@@ -3500,17 +3740,17 @@ var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
|
|
|
3500
3740
|
return this;
|
|
3501
3741
|
}
|
|
3502
3742
|
/**
|
|
3503
|
-
* Concentrates liquidity within price bounds for
|
|
3743
|
+
* Concentrates liquidity within price bounds for two tokens
|
|
3504
3744
|
**/
|
|
3505
|
-
|
|
3506
|
-
super.add(
|
|
3745
|
+
concentrateGrowLiquidity2D(data) {
|
|
3746
|
+
super.add(concentrateGrowLiquidity2D.createIx(new ConcentrateGrowLiquidity2DArgs(data.sqrtPriceMin, data.sqrtPriceMax)));
|
|
3507
3747
|
return this;
|
|
3508
3748
|
}
|
|
3509
3749
|
/**
|
|
3510
|
-
*
|
|
3750
|
+
* Square-root linear swap curve for pegged assets
|
|
3511
3751
|
**/
|
|
3512
|
-
|
|
3513
|
-
super.add(
|
|
3752
|
+
peggedSwapGrowPriceRange2D(data) {
|
|
3753
|
+
super.add(peggedSwapGrowPriceRange2D.createIx(new PeggedSwapArgs(data.x0, data.y0, data.linearWidth, data.rateLt, data.rateGt)));
|
|
3514
3754
|
return this;
|
|
3515
3755
|
}
|
|
3516
3756
|
/**
|
|
@@ -3528,38 +3768,31 @@ var AquaProgramBuilder = class AquaProgramBuilder extends ProgramBuilder {
|
|
|
3528
3768
|
return this;
|
|
3529
3769
|
}
|
|
3530
3770
|
/**
|
|
3531
|
-
* Applies fee to
|
|
3771
|
+
* Applies protocol fee to amountIn with direct transfer
|
|
3532
3772
|
**/
|
|
3533
|
-
|
|
3534
|
-
super.add(
|
|
3773
|
+
protocolFeeAmountInXD(data) {
|
|
3774
|
+
super.add(protocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3535
3775
|
return this;
|
|
3536
3776
|
}
|
|
3537
3777
|
/**
|
|
3538
|
-
* Applies
|
|
3778
|
+
* Applies protocol fee to amountIn through Aqua protocol
|
|
3539
3779
|
**/
|
|
3540
|
-
|
|
3541
|
-
super.add(
|
|
3780
|
+
aquaProtocolFeeAmountInXD(data) {
|
|
3781
|
+
super.add(aquaProtocolFeeAmountInXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3542
3782
|
return this;
|
|
3543
3783
|
}
|
|
3544
3784
|
/**
|
|
3545
|
-
* Applies
|
|
3785
|
+
* Applies protocol fee, fetched from external contract, to amountIn with direct transfer
|
|
3546
3786
|
**/
|
|
3547
|
-
|
|
3548
|
-
super.add(
|
|
3787
|
+
dynamicProtocolFeeAmountInXD(data) {
|
|
3788
|
+
super.add(dynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
|
|
3549
3789
|
return this;
|
|
3550
3790
|
}
|
|
3551
3791
|
/**
|
|
3552
|
-
* Applies protocol fee to
|
|
3792
|
+
* Applies protocol fee, fetched from external contract, to amountIn through Aqua protocol
|
|
3553
3793
|
**/
|
|
3554
|
-
|
|
3555
|
-
super.add(
|
|
3556
|
-
return this;
|
|
3557
|
-
}
|
|
3558
|
-
/**
|
|
3559
|
-
* Applies protocol fee to amountOut through Aqua protocol
|
|
3560
|
-
**/
|
|
3561
|
-
aquaProtocolFeeAmountOutXD(data) {
|
|
3562
|
-
super.add(aquaProtocolFeeAmountOutXD.createIx(new ProtocolFeeArgs(data.fee, data.to)));
|
|
3794
|
+
aquaDynamicProtocolFeeAmountInXD(data) {
|
|
3795
|
+
super.add(aquaDynamicProtocolFeeAmountInXD.createIx(new DynamicProtocolFeeArgs(data.feeProvider)));
|
|
3563
3796
|
return this;
|
|
3564
3797
|
}
|
|
3565
3798
|
/**
|
|
@@ -3722,23 +3955,12 @@ var Order = class Order {
|
|
|
3722
3955
|
|
|
3723
3956
|
//#endregion
|
|
3724
3957
|
//#region src/swap-vm/strategies/aqua-amm-strategy.ts
|
|
3725
|
-
|
|
3726
|
-
* Aqua AMM Strategy builder that mirrors AquaAMM.sol
|
|
3727
|
-
* @see https://github.com/1inch/swap-vm/blob/main/src/strategies/AquaAMM.sol
|
|
3728
|
-
*/
|
|
3729
|
-
var AquaAMMStrategy = class AquaAMMStrategy {
|
|
3958
|
+
var AquaAMMStrategy = class {
|
|
3730
3959
|
feeBpsIn;
|
|
3731
|
-
deltas;
|
|
3732
3960
|
decayPeriod;
|
|
3733
3961
|
protocolFee;
|
|
3734
3962
|
salt;
|
|
3735
|
-
constructor(
|
|
3736
|
-
this.tokenA = tokenA;
|
|
3737
|
-
this.tokenB = tokenB;
|
|
3738
|
-
}
|
|
3739
|
-
static new(tokens) {
|
|
3740
|
-
return new AquaAMMStrategy(tokens.tokenA, tokens.tokenB);
|
|
3741
|
-
}
|
|
3963
|
+
constructor() {}
|
|
3742
3964
|
withProtocolFee(bps, receiver) {
|
|
3743
3965
|
this.protocolFee = {
|
|
3744
3966
|
bps,
|
|
@@ -3746,13 +3968,6 @@ var AquaAMMStrategy = class AquaAMMStrategy {
|
|
|
3746
3968
|
};
|
|
3747
3969
|
return this;
|
|
3748
3970
|
}
|
|
3749
|
-
withDeltas(a, b) {
|
|
3750
|
-
this.deltas = {
|
|
3751
|
-
a,
|
|
3752
|
-
b
|
|
3753
|
-
};
|
|
3754
|
-
return this;
|
|
3755
|
-
}
|
|
3756
3971
|
withDecayPeriod(decayPeriod) {
|
|
3757
3972
|
this.decayPeriod = decayPeriod;
|
|
3758
3973
|
return this;
|
|
@@ -3765,22 +3980,80 @@ var AquaAMMStrategy = class AquaAMMStrategy {
|
|
|
3765
3980
|
this.salt = salt$1;
|
|
3766
3981
|
return this;
|
|
3767
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
|
+
}
|
|
3768
4006
|
build() {
|
|
3769
4007
|
const builder = new AquaProgramBuilder();
|
|
3770
|
-
if (this.
|
|
3771
|
-
const data =
|
|
3772
|
-
builder.add(
|
|
4008
|
+
if (this.protocolFee) {
|
|
4009
|
+
const data = ProtocolFeeArgs.fromBps(this.protocolFee.bps, this.protocolFee.receiver);
|
|
4010
|
+
builder.add(aquaProtocolFeeAmountInXD.createIx(data));
|
|
3773
4011
|
}
|
|
4012
|
+
if (this.xycConcentrateArgs) builder.add(concentrateGrowLiquidity2D.createIx(this.xycConcentrateArgs));
|
|
3774
4013
|
if (this.decayPeriod) builder.decayXD({ decayPeriod: this.decayPeriod });
|
|
3775
4014
|
if (this.feeBpsIn) {
|
|
3776
4015
|
const data = FlatFeeArgs.fromBps(this.feeBpsIn);
|
|
3777
4016
|
builder.add(flatFeeAmountInXD.createIx(data));
|
|
3778
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();
|
|
3779
4038
|
if (this.protocolFee) {
|
|
3780
4039
|
const data = ProtocolFeeArgs.fromBps(this.protocolFee.bps, this.protocolFee.receiver);
|
|
3781
|
-
builder.add(
|
|
4040
|
+
builder.add(aquaProtocolFeeAmountInXD.createIx(data));
|
|
3782
4041
|
}
|
|
3783
|
-
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);
|
|
3784
4057
|
if (this.salt) builder.salt({ salt: this.salt });
|
|
3785
4058
|
return builder.build();
|
|
3786
4059
|
}
|
|
@@ -3806,7 +4079,9 @@ Object.defineProperty(exports, 'Address', {
|
|
|
3806
4079
|
}
|
|
3807
4080
|
});
|
|
3808
4081
|
exports.AquaAMMStrategy = AquaAMMStrategy;
|
|
4082
|
+
exports.AquaPeggedAmmStrategy = AquaPeggedAmmStrategy;
|
|
3809
4083
|
exports.AquaProgramBuilder = AquaProgramBuilder;
|
|
4084
|
+
exports.AquaXYCAmmStrategy = AquaXYCAmmStrategy;
|
|
3810
4085
|
Object.defineProperty(exports, 'CallInfo', {
|
|
3811
4086
|
enumerable: true,
|
|
3812
4087
|
get: function () {
|