@1delta/calldatalib 0.0.27 → 0.0.30

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.
@@ -67,6 +67,7 @@ export declare enum Gen2025ActionIds {
67
67
  export declare enum ComposerCommands {
68
68
  SWAPS = 16,
69
69
  EXT_CALL = 32,
70
+ EXT_TRY_CALL = 33,
70
71
  LENDING = 48,
71
72
  TRANSFERS = 64,
72
73
  PERMIT = 80,
@@ -108,7 +109,8 @@ export declare enum DexForkMappings {
108
109
  BALANCER_V3 = 0,
109
110
  UNISWAP_V2 = 0
110
111
  }
111
- export declare function encodeExternalCall(target: Address, value: bigint, data: Hex): Hex;
112
+ export declare function encodeExternalCall(target: Address, value: bigint, useSelfBalance: boolean, data: Hex): Hex;
113
+ export declare function encodeTryExternalCall(target: Address, value: bigint, useSelfBalance: boolean, rOnFailure: boolean, data: Hex, catchData: Hex): Hex;
112
114
  export declare function encodeStargateV2Bridge(asset: Address, stargatePool: Address, dstEid: number, receiver: Hex, refundReceiver: Address, amount: bigint, slippage: number, fee: bigint, isBusMode: boolean, isNative: boolean, composeMsg: Hex, extraOptions: Hex): Hex;
113
115
  export declare function encodeStargateV2BridgePartial(amount: bigint, slippage: number, fee: bigint, isBusMode: boolean, isNative: boolean, composeMsg: Hex, extraOptions: Hex): Hex;
114
116
  export declare function encodeStargateV2BridgeSimpleTaxi(asset: Address, stargatePool: Address, dstEid: number, receiver: Hex, refundReceiver: Address, amount: bigint, isNative: boolean, slippage: number, fee: bigint): Hex;
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
2
  import { zeroAddress } from "viem";
3
- import { encodePacked, uint128, uint8, uint112, uint16, uint256, generateAmountBitmap, newbytes, bytes, getMorphoCollateral, getMorphoLoanAsset, } from "./utils.js";
3
+ import { encodePacked, uint128, uint8, uint16, uint256, generateAmountBitmap, newbytes, bytes, getMorphoCollateral, getMorphoLoanAsset, } from "./utils.js";
4
4
  export var SweepType;
5
5
  (function (SweepType) {
6
6
  SweepType[SweepType["VALIDATE"] = 0] = "VALIDATE";
@@ -81,6 +81,7 @@ export var ComposerCommands;
81
81
  (function (ComposerCommands) {
82
82
  ComposerCommands[ComposerCommands["SWAPS"] = 16] = "SWAPS";
83
83
  ComposerCommands[ComposerCommands["EXT_CALL"] = 32] = "EXT_CALL";
84
+ ComposerCommands[ComposerCommands["EXT_TRY_CALL"] = 33] = "EXT_TRY_CALL";
84
85
  ComposerCommands[ComposerCommands["LENDING"] = 48] = "LENDING";
85
86
  ComposerCommands[ComposerCommands["TRANSFERS"] = 64] = "TRANSFERS";
86
87
  ComposerCommands[ComposerCommands["PERMIT"] = 80] = "PERMIT";
@@ -125,8 +126,26 @@ export var DexForkMappings;
125
126
  DexForkMappings[DexForkMappings["BALANCER_V3"] = 0] = "BALANCER_V3";
126
127
  DexForkMappings[DexForkMappings["UNISWAP_V2"] = 0] = "UNISWAP_V2";
127
128
  })(DexForkMappings || (DexForkMappings = {}));
128
- export function encodeExternalCall(target, value, data) {
129
- return encodePacked(["uint8", "address", "uint112", "uint16", "bytes"], [uint8(ComposerCommands.EXT_CALL), target, uint112(value), uint16(data.length / 2 - 1), data]);
129
+ export function encodeExternalCall(target, value, useSelfBalance, data) {
130
+ return encodePacked(["uint8", "address", "uint128", "uint16", "bytes"], [
131
+ uint8(ComposerCommands.EXT_CALL),
132
+ target,
133
+ generateAmountBitmap(uint128(value), false, false, useSelfBalance),
134
+ uint16(data.length / 2 - 1),
135
+ data,
136
+ ]);
137
+ }
138
+ export function encodeTryExternalCall(target, value, useSelfBalance, rOnFailure, data, catchData) {
139
+ return encodePacked(["uint8", "address", "uint128", "uint16", "bytes", "uint8", "uint16", "bytes"], [
140
+ uint8(ComposerCommands.EXT_TRY_CALL),
141
+ target,
142
+ generateAmountBitmap(uint128(value), false, false, useSelfBalance),
143
+ uint16(data.length / 2 - 1),
144
+ data,
145
+ uint8(rOnFailure ? 0 : 1),
146
+ uint16(catchData.length / 2 - 1),
147
+ catchData,
148
+ ]);
130
149
  }
131
150
  export function encodeStargateV2Bridge(asset, stargatePool, dstEid, receiver, refundReceiver, amount, slippage, fee, isBusMode, isNative, composeMsg, extraOptions) {
132
151
  const partialData = encodeStargateV2BridgePartial(amount, slippage, fee, isBusMode, isNative, composeMsg, extraOptions);
@@ -327,14 +346,14 @@ export function encodeUniswapV4StyleSwap(currentData, tokenOut, receiver, manage
327
346
  export function encodeBalancerV2StyleSwap(currentData, tokenOut, receiver, poolId, balancerVault, cfg) {
328
347
  if (cfg === DexPayConfig.FLASH)
329
348
  throw new Error("Invalidconfigforv2swap");
330
- return encodePacked(["bytes", "address", "address", "uint8", "bytes32", "address", "uint16"], [
349
+ return encodePacked(["bytes", "address", "address", "uint8", "bytes32", "address", "uint8"], [
331
350
  currentData,
332
351
  tokenOut,
333
352
  receiver,
334
353
  uint8(DexTypeMappings.BALANCER_V2_ID),
335
354
  poolId,
336
355
  balancerVault,
337
- uint16(uint256(cfg)),
356
+ uint8(uint256(cfg)),
338
357
  ]);
339
358
  }
340
359
  export function encodeLbStyleSwap(currentData, tokenOut, receiver, pool, swapForY, cfg) {
@@ -345,7 +364,7 @@ export function encodeLbStyleSwap(currentData, tokenOut, receiver, pool, swapFor
345
364
  export function encodeSyncSwapStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
346
365
  if (cfg === DexPayConfig.FLASH)
347
366
  throw new Error("Invalidconfigforv2swap");
348
- return encodePacked(["bytes", "address", "address", "uint8", "address", "uint16"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.SYNC_SWAP_ID), pool, uint16(uint256(cfg))]);
367
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.SYNC_SWAP_ID), pool, uint8(uint256(cfg))]);
349
368
  }
350
369
  export function encodeUniswapV3StyleSwap(currentData, tokenOut, receiver, forkId, pool, feeTier, cfg, flashCalldata) {
351
370
  if (uint256(cfg) < 2 && flashCalldata.length / 2 - 1 > 2)
@@ -67,6 +67,7 @@ export declare enum Gen2025ActionIds {
67
67
  export declare enum ComposerCommands {
68
68
  SWAPS = 16,
69
69
  EXT_CALL = 32,
70
+ EXT_TRY_CALL = 33,
70
71
  LENDING = 48,
71
72
  TRANSFERS = 64,
72
73
  PERMIT = 80,
@@ -108,7 +109,8 @@ export declare enum DexForkMappings {
108
109
  BALANCER_V3 = 0,
109
110
  UNISWAP_V2 = 0
110
111
  }
111
- export declare function encodeExternalCall(target: Address, value: bigint, data: Hex): Hex;
112
+ export declare function encodeExternalCall(target: Address, value: bigint, useSelfBalance: boolean, data: Hex): Hex;
113
+ export declare function encodeTryExternalCall(target: Address, value: bigint, useSelfBalance: boolean, rOnFailure: boolean, data: Hex, catchData: Hex): Hex;
112
114
  export declare function encodeStargateV2Bridge(asset: Address, stargatePool: Address, dstEid: number, receiver: Hex, refundReceiver: Address, amount: bigint, slippage: number, fee: bigint, isBusMode: boolean, isNative: boolean, composeMsg: Hex, extraOptions: Hex): Hex;
113
115
  export declare function encodeStargateV2BridgePartial(amount: bigint, slippage: number, fee: bigint, isBusMode: boolean, isNative: boolean, composeMsg: Hex, extraOptions: Hex): Hex;
114
116
  export declare function encodeStargateV2BridgeSimpleTaxi(asset: Address, stargatePool: Address, dstEid: number, receiver: Hex, refundReceiver: Address, amount: bigint, isNative: boolean, slippage: number, fee: bigint): Hex;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DexForkMappings = exports.DexTypeMappings = exports.BridgeIds = exports.ComposerCommands = exports.Gen2025ActionIds = exports.ERC4626Ids = exports.FlashLoanIds = exports.LenderOps = exports.LenderIds = exports.PermitIds = exports.TransferIds = exports.WrapOperation = exports.DodoSelector = exports.DexPayConfig = exports.SweepType = void 0;
4
4
  exports.encodeExternalCall = encodeExternalCall;
5
+ exports.encodeTryExternalCall = encodeTryExternalCall;
5
6
  exports.encodeStargateV2Bridge = encodeStargateV2Bridge;
6
7
  exports.encodeStargateV2BridgePartial = encodeStargateV2BridgePartial;
7
8
  exports.encodeStargateV2BridgeSimpleTaxi = encodeStargateV2BridgeSimpleTaxi;
@@ -152,6 +153,7 @@ var ComposerCommands;
152
153
  (function (ComposerCommands) {
153
154
  ComposerCommands[ComposerCommands["SWAPS"] = 16] = "SWAPS";
154
155
  ComposerCommands[ComposerCommands["EXT_CALL"] = 32] = "EXT_CALL";
156
+ ComposerCommands[ComposerCommands["EXT_TRY_CALL"] = 33] = "EXT_TRY_CALL";
155
157
  ComposerCommands[ComposerCommands["LENDING"] = 48] = "LENDING";
156
158
  ComposerCommands[ComposerCommands["TRANSFERS"] = 64] = "TRANSFERS";
157
159
  ComposerCommands[ComposerCommands["PERMIT"] = 80] = "PERMIT";
@@ -196,8 +198,26 @@ var DexForkMappings;
196
198
  DexForkMappings[DexForkMappings["BALANCER_V3"] = 0] = "BALANCER_V3";
197
199
  DexForkMappings[DexForkMappings["UNISWAP_V2"] = 0] = "UNISWAP_V2";
198
200
  })(DexForkMappings || (exports.DexForkMappings = DexForkMappings = {}));
199
- function encodeExternalCall(target, value, data) {
200
- return (0, utils_js_1.encodePacked)(["uint8", "address", "uint112", "uint16", "bytes"], [(0, utils_js_1.uint8)(ComposerCommands.EXT_CALL), target, (0, utils_js_1.uint112)(value), (0, utils_js_1.uint16)(data.length / 2 - 1), data]);
201
+ function encodeExternalCall(target, value, useSelfBalance, data) {
202
+ return (0, utils_js_1.encodePacked)(["uint8", "address", "uint128", "uint16", "bytes"], [
203
+ (0, utils_js_1.uint8)(ComposerCommands.EXT_CALL),
204
+ target,
205
+ (0, utils_js_1.generateAmountBitmap)((0, utils_js_1.uint128)(value), false, false, useSelfBalance),
206
+ (0, utils_js_1.uint16)(data.length / 2 - 1),
207
+ data,
208
+ ]);
209
+ }
210
+ function encodeTryExternalCall(target, value, useSelfBalance, rOnFailure, data, catchData) {
211
+ return (0, utils_js_1.encodePacked)(["uint8", "address", "uint128", "uint16", "bytes", "uint8", "uint16", "bytes"], [
212
+ (0, utils_js_1.uint8)(ComposerCommands.EXT_TRY_CALL),
213
+ target,
214
+ (0, utils_js_1.generateAmountBitmap)((0, utils_js_1.uint128)(value), false, false, useSelfBalance),
215
+ (0, utils_js_1.uint16)(data.length / 2 - 1),
216
+ data,
217
+ (0, utils_js_1.uint8)(rOnFailure ? 0 : 1),
218
+ (0, utils_js_1.uint16)(catchData.length / 2 - 1),
219
+ catchData,
220
+ ]);
201
221
  }
202
222
  function encodeStargateV2Bridge(asset, stargatePool, dstEid, receiver, refundReceiver, amount, slippage, fee, isBusMode, isNative, composeMsg, extraOptions) {
203
223
  const partialData = encodeStargateV2BridgePartial(amount, slippage, fee, isBusMode, isNative, composeMsg, extraOptions);
@@ -398,14 +418,14 @@ function encodeUniswapV4StyleSwap(currentData, tokenOut, receiver, manager, fee,
398
418
  function encodeBalancerV2StyleSwap(currentData, tokenOut, receiver, poolId, balancerVault, cfg) {
399
419
  if (cfg === DexPayConfig.FLASH)
400
420
  throw new Error("Invalidconfigforv2swap");
401
- return (0, utils_js_1.encodePacked)(["bytes", "address", "address", "uint8", "bytes32", "address", "uint16"], [
421
+ return (0, utils_js_1.encodePacked)(["bytes", "address", "address", "uint8", "bytes32", "address", "uint8"], [
402
422
  currentData,
403
423
  tokenOut,
404
424
  receiver,
405
425
  (0, utils_js_1.uint8)(DexTypeMappings.BALANCER_V2_ID),
406
426
  poolId,
407
427
  balancerVault,
408
- (0, utils_js_1.uint16)((0, utils_js_1.uint256)(cfg)),
428
+ (0, utils_js_1.uint8)((0, utils_js_1.uint256)(cfg)),
409
429
  ]);
410
430
  }
411
431
  function encodeLbStyleSwap(currentData, tokenOut, receiver, pool, swapForY, cfg) {
@@ -416,7 +436,7 @@ function encodeLbStyleSwap(currentData, tokenOut, receiver, pool, swapForY, cfg)
416
436
  function encodeSyncSwapStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
417
437
  if (cfg === DexPayConfig.FLASH)
418
438
  throw new Error("Invalidconfigforv2swap");
419
- return (0, utils_js_1.encodePacked)(["bytes", "address", "address", "uint8", "address", "uint16"], [currentData, tokenOut, receiver, (0, utils_js_1.uint8)(DexTypeMappings.SYNC_SWAP_ID), pool, (0, utils_js_1.uint16)((0, utils_js_1.uint256)(cfg))]);
439
+ return (0, utils_js_1.encodePacked)(["bytes", "address", "address", "uint8", "address", "uint8"], [currentData, tokenOut, receiver, (0, utils_js_1.uint8)(DexTypeMappings.SYNC_SWAP_ID), pool, (0, utils_js_1.uint8)((0, utils_js_1.uint256)(cfg))]);
420
440
  }
421
441
  function encodeUniswapV3StyleSwap(currentData, tokenOut, receiver, forkId, pool, feeTier, cfg, flashCalldata) {
422
442
  if ((0, utils_js_1.uint256)(cfg) < 2 && flashCalldata.length / 2 - 1 > 2)
@@ -0,0 +1,839 @@
1
+ // @ts-nocheck
2
+ import { zeroAddress } from "viem";
3
+ import { encodePacked, uint128, uint8, uint16, uint256, generateAmountBitmap, newbytes, bytes, getMorphoCollateral, getMorphoLoanAsset, } from "./utils.js";
4
+ export var SweepType;
5
+ (function (SweepType) {
6
+ SweepType[SweepType["VALIDATE"] = 0] = "VALIDATE";
7
+ SweepType[SweepType["AMOUNT"] = 1] = "AMOUNT";
8
+ })(SweepType || (SweepType = {}));
9
+ export var DexPayConfig;
10
+ (function (DexPayConfig) {
11
+ DexPayConfig[DexPayConfig["CALLER_PAYS"] = 0] = "CALLER_PAYS";
12
+ DexPayConfig[DexPayConfig["CONTRACT_PAYS"] = 1] = "CONTRACT_PAYS";
13
+ DexPayConfig[DexPayConfig["PRE_FUND"] = 2] = "PRE_FUND";
14
+ DexPayConfig[DexPayConfig["FLASH"] = 3] = "FLASH";
15
+ })(DexPayConfig || (DexPayConfig = {}));
16
+ export var DodoSelector;
17
+ (function (DodoSelector) {
18
+ DodoSelector[DodoSelector["SELL_BASE"] = 0] = "SELL_BASE";
19
+ DodoSelector[DodoSelector["SELL_QUOTE"] = 1] = "SELL_QUOTE";
20
+ })(DodoSelector || (DodoSelector = {}));
21
+ export var WrapOperation;
22
+ (function (WrapOperation) {
23
+ WrapOperation[WrapOperation["NATIVE"] = 0] = "NATIVE";
24
+ WrapOperation[WrapOperation["ERC4626_DEPOSIT"] = 1] = "ERC4626_DEPOSIT";
25
+ WrapOperation[WrapOperation["ERC4626_REDEEM"] = 2] = "ERC4626_REDEEM";
26
+ })(WrapOperation || (WrapOperation = {}));
27
+ export var TransferIds;
28
+ (function (TransferIds) {
29
+ TransferIds[TransferIds["TRANSFER_FROM"] = 0] = "TRANSFER_FROM";
30
+ TransferIds[TransferIds["SWEEP"] = 1] = "SWEEP";
31
+ TransferIds[TransferIds["WRAP_NATIVE"] = 2] = "WRAP_NATIVE";
32
+ TransferIds[TransferIds["UNWRAP_WNATIVE"] = 3] = "UNWRAP_WNATIVE";
33
+ TransferIds[TransferIds["PERMIT2_TRANSFER_FROM"] = 4] = "PERMIT2_TRANSFER_FROM";
34
+ TransferIds[TransferIds["APPROVE"] = 5] = "APPROVE";
35
+ })(TransferIds || (TransferIds = {}));
36
+ export var PermitIds;
37
+ (function (PermitIds) {
38
+ PermitIds[PermitIds["TOKEN_PERMIT"] = 0] = "TOKEN_PERMIT";
39
+ PermitIds[PermitIds["AAVE_V3_CREDIT_PERMIT"] = 1] = "AAVE_V3_CREDIT_PERMIT";
40
+ PermitIds[PermitIds["ALLOW_CREDIT_PERMIT"] = 2] = "ALLOW_CREDIT_PERMIT";
41
+ })(PermitIds || (PermitIds = {}));
42
+ export var LenderIds;
43
+ (function (LenderIds) {
44
+ LenderIds[LenderIds["UP_TO_AAVE_V3"] = 1000] = "UP_TO_AAVE_V3";
45
+ LenderIds[LenderIds["UP_TO_AAVE_V2"] = 2000] = "UP_TO_AAVE_V2";
46
+ LenderIds[LenderIds["UP_TO_COMPOUND_V3"] = 3000] = "UP_TO_COMPOUND_V3";
47
+ LenderIds[LenderIds["UP_TO_COMPOUND_V2"] = 4000] = "UP_TO_COMPOUND_V2";
48
+ LenderIds[LenderIds["UP_TO_MORPHO"] = 5000] = "UP_TO_MORPHO";
49
+ })(LenderIds || (LenderIds = {}));
50
+ export var LenderOps;
51
+ (function (LenderOps) {
52
+ LenderOps[LenderOps["DEPOSIT"] = 0] = "DEPOSIT";
53
+ LenderOps[LenderOps["BORROW"] = 1] = "BORROW";
54
+ LenderOps[LenderOps["REPAY"] = 2] = "REPAY";
55
+ LenderOps[LenderOps["WITHDRAW"] = 3] = "WITHDRAW";
56
+ LenderOps[LenderOps["DEPOSIT_LENDING_TOKEN"] = 4] = "DEPOSIT_LENDING_TOKEN";
57
+ LenderOps[LenderOps["WITHDRAW_LENDING_TOKEN"] = 5] = "WITHDRAW_LENDING_TOKEN";
58
+ })(LenderOps || (LenderOps = {}));
59
+ export var FlashLoanIds;
60
+ (function (FlashLoanIds) {
61
+ FlashLoanIds[FlashLoanIds["MORPHO"] = 0] = "MORPHO";
62
+ FlashLoanIds[FlashLoanIds["BALANCER_V2"] = 1] = "BALANCER_V2";
63
+ FlashLoanIds[FlashLoanIds["AAVE_V3"] = 2] = "AAVE_V3";
64
+ FlashLoanIds[FlashLoanIds["AAVE_V2"] = 3] = "AAVE_V2";
65
+ })(FlashLoanIds || (FlashLoanIds = {}));
66
+ export var ERC4626Ids;
67
+ (function (ERC4626Ids) {
68
+ ERC4626Ids[ERC4626Ids["DEPOSIT"] = 0] = "DEPOSIT";
69
+ ERC4626Ids[ERC4626Ids["WITHDRAW"] = 1] = "WITHDRAW";
70
+ })(ERC4626Ids || (ERC4626Ids = {}));
71
+ export var Gen2025ActionIds;
72
+ (function (Gen2025ActionIds) {
73
+ Gen2025ActionIds[Gen2025ActionIds["UNLOCK"] = 0] = "UNLOCK";
74
+ Gen2025ActionIds[Gen2025ActionIds["UNI_V4_TAKE"] = 1] = "UNI_V4_TAKE";
75
+ Gen2025ActionIds[Gen2025ActionIds["UNI_V4_SETTLE"] = 2] = "UNI_V4_SETTLE";
76
+ Gen2025ActionIds[Gen2025ActionIds["UNI_V4_SYNC"] = 3] = "UNI_V4_SYNC";
77
+ Gen2025ActionIds[Gen2025ActionIds["BAL_V3_TAKE"] = 4] = "BAL_V3_TAKE";
78
+ Gen2025ActionIds[Gen2025ActionIds["BAL_V3_SETTLE"] = 5] = "BAL_V3_SETTLE";
79
+ })(Gen2025ActionIds || (Gen2025ActionIds = {}));
80
+ export var ComposerCommands;
81
+ (function (ComposerCommands) {
82
+ ComposerCommands[ComposerCommands["SWAPS"] = 16] = "SWAPS";
83
+ ComposerCommands[ComposerCommands["EXT_CALL"] = 32] = "EXT_CALL";
84
+ ComposerCommands[ComposerCommands["EXT_TRY_CALL"] = 33] = "EXT_TRY_CALL";
85
+ ComposerCommands[ComposerCommands["LENDING"] = 48] = "LENDING";
86
+ ComposerCommands[ComposerCommands["TRANSFERS"] = 64] = "TRANSFERS";
87
+ ComposerCommands[ComposerCommands["PERMIT"] = 80] = "PERMIT";
88
+ ComposerCommands[ComposerCommands["FLASH_LOAN"] = 96] = "FLASH_LOAN";
89
+ ComposerCommands[ComposerCommands["ERC4626"] = 112] = "ERC4626";
90
+ ComposerCommands[ComposerCommands["GEN_2025_SINGELTONS"] = 128] = "GEN_2025_SINGELTONS";
91
+ ComposerCommands[ComposerCommands["BRIDGING"] = 144] = "BRIDGING";
92
+ })(ComposerCommands || (ComposerCommands = {}));
93
+ export var BridgeIds;
94
+ (function (BridgeIds) {
95
+ BridgeIds[BridgeIds["STARGATE_V2"] = 0] = "STARGATE_V2";
96
+ BridgeIds[BridgeIds["ACROSS"] = 10] = "ACROSS";
97
+ })(BridgeIds || (BridgeIds = {}));
98
+ export var DexTypeMappings;
99
+ (function (DexTypeMappings) {
100
+ DexTypeMappings[DexTypeMappings["UNISWAP_V3_ID"] = 0] = "UNISWAP_V3_ID";
101
+ DexTypeMappings[DexTypeMappings["UNISWAP_V2_ID"] = 1] = "UNISWAP_V2_ID";
102
+ DexTypeMappings[DexTypeMappings["UNISWAP_V4_ID"] = 2] = "UNISWAP_V4_ID";
103
+ DexTypeMappings[DexTypeMappings["IZI_ID"] = 5] = "IZI_ID";
104
+ DexTypeMappings[DexTypeMappings["UNISWAP_V2_FOT_ID"] = 3] = "UNISWAP_V2_FOT_ID";
105
+ DexTypeMappings[DexTypeMappings["CURVE_V1_STANDARD_ID"] = 64] = "CURVE_V1_STANDARD_ID";
106
+ DexTypeMappings[DexTypeMappings["CURVE_RECEIVED_ID"] = 65] = "CURVE_RECEIVED_ID";
107
+ DexTypeMappings[DexTypeMappings["CURVE_FORK_ID"] = 66] = "CURVE_FORK_ID";
108
+ DexTypeMappings[DexTypeMappings["WOO_FI_ID"] = 80] = "WOO_FI_ID";
109
+ DexTypeMappings[DexTypeMappings["GMX_ID"] = 90] = "GMX_ID";
110
+ DexTypeMappings[DexTypeMappings["KTX_ID"] = 91] = "KTX_ID";
111
+ DexTypeMappings[DexTypeMappings["BALANCER_V2_ID"] = 128] = "BALANCER_V2_ID";
112
+ DexTypeMappings[DexTypeMappings["BALANCER_V3_ID"] = 129] = "BALANCER_V3_ID";
113
+ DexTypeMappings[DexTypeMappings["LB_ID"] = 140] = "LB_ID";
114
+ DexTypeMappings[DexTypeMappings["DODO_ID"] = 150] = "DODO_ID";
115
+ DexTypeMappings[DexTypeMappings["SYNC_SWAP_ID"] = 160] = "SYNC_SWAP_ID";
116
+ DexTypeMappings[DexTypeMappings["ERC4626_ID"] = 253] = "ERC4626_ID";
117
+ DexTypeMappings[DexTypeMappings["ASSET_WRAP_ID"] = 254] = "ASSET_WRAP_ID";
118
+ })(DexTypeMappings || (DexTypeMappings = {}));
119
+ export var DexForkMappings;
120
+ (function (DexForkMappings) {
121
+ DexForkMappings[DexForkMappings["UNISWAP_V3"] = 0] = "UNISWAP_V3";
122
+ DexForkMappings[DexForkMappings["IZI"] = 0] = "IZI";
123
+ DexForkMappings[DexForkMappings["ANY_V3"] = 255] = "ANY_V3";
124
+ DexForkMappings[DexForkMappings["ANY_IZI"] = 255] = "ANY_IZI";
125
+ DexForkMappings[DexForkMappings["UNISWAP_V4"] = 0] = "UNISWAP_V4";
126
+ DexForkMappings[DexForkMappings["BALANCER_V3"] = 0] = "BALANCER_V3";
127
+ DexForkMappings[DexForkMappings["UNISWAP_V2"] = 0] = "UNISWAP_V2";
128
+ })(DexForkMappings || (DexForkMappings = {}));
129
+ export function encodeExternalCall(target, value, useSelfBalance, data) {
130
+ return encodePacked(["uint8", "address", "uint128", "uint16", "bytes"], [
131
+ uint8(ComposerCommands.EXT_CALL),
132
+ target,
133
+ generateAmountBitmap(uint128(value), false, false, useSelfBalance),
134
+ uint16(data.length / 2 - 1),
135
+ data,
136
+ ]);
137
+ }
138
+ export function encodeTryExternalCall(target, value, useSelfBalance, rOnFailure, data, catchData) {
139
+ return encodePacked(["uint8", "address", "uint128", "uint16", "bytes", "uint8", "uint16", "bytes"], [
140
+ uint8(ComposerCommands.EXT_TRY_CALL),
141
+ target,
142
+ generateAmountBitmap(uint128(value), false, false, useSelfBalance),
143
+ uint16(data.length / 2 - 1),
144
+ data,
145
+ uint8(rOnFailure ? 0 : 1),
146
+ uint16(catchData.length / 2 - 1),
147
+ catchData,
148
+ ]);
149
+ }
150
+ export function encodeStargateV2Bridge(asset, stargatePool, dstEid, receiver, refundReceiver, amount, slippage, fee, isBusMode, isNative, composeMsg, extraOptions) {
151
+ const partialData = encodeStargateV2BridgePartial(amount, slippage, fee, isBusMode, isNative, composeMsg, extraOptions);
152
+ return encodePacked(["uint8", "uint8", "address", "address", "uint32", "bytes32", "address", "bytes"], [
153
+ uint8(ComposerCommands.BRIDGING),
154
+ uint8(BridgeIds.STARGATE_V2),
155
+ asset,
156
+ stargatePool,
157
+ dstEid,
158
+ receiver,
159
+ refundReceiver,
160
+ partialData,
161
+ ]);
162
+ }
163
+ export function encodeStargateV2BridgePartial(amount, slippage, fee, isBusMode, isNative, composeMsg, extraOptions) {
164
+ return encodePacked(["uint128", "uint32", "uint128", "uint8", "uint16", "uint16", "bytes", "bytes"], [
165
+ generateAmountBitmap(uint128(amount), false, false, isNative),
166
+ slippage,
167
+ uint128(fee),
168
+ uint8(isBusMode ? 1 : 0),
169
+ uint16(composeMsg.length / 2 - 1),
170
+ uint16(extraOptions.length / 2 - 1),
171
+ composeMsg,
172
+ extraOptions,
173
+ ]);
174
+ }
175
+ export function encodeStargateV2BridgeSimpleTaxi(asset, stargatePool, dstEid, receiver, refundReceiver, amount, isNative, slippage, fee) {
176
+ return encodeStargateV2Bridge(asset, stargatePool, dstEid, receiver, refundReceiver, amount, slippage, fee, false, isNative, newbytes(0), newbytes(0));
177
+ }
178
+ export function encodeStargateV2BridgeSimpleBus(asset, stargatePool, dstEid, receiver, refundReceiver, amount, isNative, slippage, fee) {
179
+ return encodeStargateV2Bridge(asset, stargatePool, dstEid, receiver, refundReceiver, amount, slippage, fee, true, isNative, newbytes(0), newbytes(0));
180
+ }
181
+ export function encodeAcrossBridgeToken(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, receiver, message) {
182
+ const bridgeData = encodePacked([
183
+ "uint8",
184
+ "uint8",
185
+ "address",
186
+ "address",
187
+ "address",
188
+ "address",
189
+ "uint128",
190
+ "uint128",
191
+ "uint32",
192
+ "uint32",
193
+ "address",
194
+ "uint16",
195
+ "bytes",
196
+ ], [
197
+ uint8(ComposerCommands.BRIDGING),
198
+ uint8(BridgeIds.ACROSS),
199
+ spokePool,
200
+ depositor,
201
+ sendingAssetId,
202
+ receivingAssetId,
203
+ generateAmountBitmap(uint128(amount), false, false, false),
204
+ fixedFee,
205
+ feePercentage,
206
+ destinationChainId,
207
+ receiver,
208
+ uint16(message.length / 2 - 1),
209
+ message,
210
+ ]);
211
+ return bridgeData;
212
+ }
213
+ export function encodeAcrossBridgeNative(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, receiver, message) {
214
+ const bridgeData = encodePacked([
215
+ "uint8",
216
+ "uint8",
217
+ "address",
218
+ "address",
219
+ "address",
220
+ "address",
221
+ "uint128",
222
+ "uint128",
223
+ "uint32",
224
+ "uint32",
225
+ "address",
226
+ "uint16",
227
+ "bytes",
228
+ ], [
229
+ uint8(ComposerCommands.BRIDGING),
230
+ uint8(BridgeIds.ACROSS),
231
+ spokePool,
232
+ depositor,
233
+ sendingAssetId,
234
+ receivingAssetId,
235
+ generateAmountBitmap(uint128(amount), false, false, true),
236
+ fixedFee,
237
+ feePercentage,
238
+ destinationChainId,
239
+ receiver,
240
+ uint16(message.length / 2 - 1),
241
+ message,
242
+ ]);
243
+ return bridgeData;
244
+ }
245
+ export function encodePermit2TransferFrom(token, receiver, amount) {
246
+ return encodePacked(["uint8", "uint8", "address", "address", "uint128"], [uint8(ComposerCommands.TRANSFERS), uint8(TransferIds.PERMIT2_TRANSFER_FROM), token, receiver, uint128(amount)]);
247
+ }
248
+ export function encodeNextGenDexUnlock(singleton, id, d) {
249
+ return encodePacked(["uint8", "uint8", "address", "uint16", "uint8", "bytes"], [
250
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
251
+ uint8(Gen2025ActionIds.UNLOCK),
252
+ singleton,
253
+ uint16(d.length / 2 - 1 + 1),
254
+ uint8(id),
255
+ d,
256
+ ]);
257
+ }
258
+ export function encodeBalancerV3FlashLoan(singleton, poolId, asset, receiver, amount, flashData) {
259
+ const take = encodeBalancerV3Take(singleton, asset, receiver, amount);
260
+ const settle = encodeNextGenDexSettleBalancer(singleton, asset, amount);
261
+ return encodeNextGenDexUnlock(singleton, poolId, encodeBalancerV3FlashLoanData(take, flashData, settle));
262
+ }
263
+ export function encodeBalancerV3FlashLoanData(take, flashData, settle) {
264
+ return encodePacked(["bytes", "bytes", "bytes"], [take, flashData, settle]);
265
+ }
266
+ export function encodeUniswapV4FlashLoan(singleton, poolId, asset, receiver, amount, flashData) {
267
+ const take = encodeUniswapV4Take(singleton, asset, receiver, amount);
268
+ const settle = encodeNextGenDexSettle(singleton, asset === zeroAddress ? amount : 0);
269
+ const sync = encodeUniswapV4Sync(singleton, asset);
270
+ return encodeNextGenDexUnlock(singleton, poolId, encodeUniswapV4FlashLoanData(take, sync, flashData, settle));
271
+ }
272
+ export function encodeUniswapV4FlashLoanData(take, sync, flashData, settle) {
273
+ return encodePacked(["bytes", "bytes", "bytes", "bytes"], [take, sync, flashData, settle]);
274
+ }
275
+ export function encodeBalancerV3Take(singleton, asset, receiver, amount) {
276
+ return encodePacked(["uint8", "uint8", "address", "address", "address", "uint128"], [
277
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
278
+ uint8(Gen2025ActionIds.BAL_V3_TAKE),
279
+ singleton,
280
+ asset,
281
+ receiver,
282
+ uint128(amount),
283
+ ]);
284
+ }
285
+ export function encodeUniswapV4Sync(singleton, asset) {
286
+ if (asset === zeroAddress)
287
+ return `0x0`;
288
+ return encodePacked(["uint8", "uint8", "address", "address"], [uint8(ComposerCommands.GEN_2025_SINGELTONS), uint8(Gen2025ActionIds.UNI_V4_SYNC), singleton, asset]);
289
+ }
290
+ export function encodeUniswapV4Take(singleton, asset, receiver, amount) {
291
+ return encodePacked(["uint8", "uint8", "address", "address", "address", "uint128"], [
292
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
293
+ uint8(Gen2025ActionIds.UNI_V4_TAKE),
294
+ singleton,
295
+ asset,
296
+ receiver,
297
+ uint128(amount),
298
+ ]);
299
+ }
300
+ export function swapHead(amount, amountOutMin, assetIn) {
301
+ return encodePacked(["uint8", "uint128", "uint128", "address"], [
302
+ uint8(ComposerCommands.SWAPS),
303
+ generateAmountBitmap(uint128(amount), false, false, false),
304
+ uint128(amountOutMin),
305
+ assetIn,
306
+ ]);
307
+ }
308
+ export function attachBranch(data, hops, splits, splitsData) {
309
+ if (hops !== 0n && splits !== 0n)
310
+ throw new Error("Invalidbranching");
311
+ if (splitsData.length / 2 - 1 > 0 && splits === 0n)
312
+ throw new Error("Nosplitsbutsplitdataprovided");
313
+ return encodePacked(["bytes", "uint8", "uint8", "bytes"], [data, uint8(hops), uint8(splits), splitsData]);
314
+ }
315
+ export function encodeUniswapV2StyleSwap(tokenOut, receiver, forkId, pool, feeDenom, cfg, flashCalldata) {
316
+ if (uint256(cfg) < 2 && flashCalldata.length / 2 - 1 > 2)
317
+ throw new Error("Invalidconfigforv2swap");
318
+ return encodePacked(["address", "address", "uint8", "address", "uint16", "uint8", "uint16", "bytes"], [
319
+ tokenOut,
320
+ receiver,
321
+ uint8(DexTypeMappings.UNISWAP_V2_ID),
322
+ pool,
323
+ uint16(feeDenom),
324
+ uint8(forkId),
325
+ uint16(cfg === DexPayConfig.FLASH ? flashCalldata.length / 2 - 1 : uint256(cfg)),
326
+ bytes(cfg === DexPayConfig.FLASH ? flashCalldata : newbytes(0)),
327
+ ]);
328
+ }
329
+ export function encodeUniswapV4StyleSwap(currentData, tokenOut, receiver, manager, fee, tickSpacing, hooks, hookData, cfg) {
330
+ if (cfg === DexPayConfig.FLASH)
331
+ throw new Error("Invalidconfigforv2swap");
332
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "address", "uint24", "uint24", "uint8", "uint16", "bytes"], [
333
+ currentData,
334
+ tokenOut,
335
+ receiver,
336
+ uint8(DexTypeMappings.UNISWAP_V4_ID),
337
+ hooks,
338
+ manager,
339
+ fee,
340
+ tickSpacing,
341
+ uint8(uint256(cfg)),
342
+ uint16(hookData.length / 2 - 1),
343
+ hookData,
344
+ ]);
345
+ }
346
+ export function encodeBalancerV2StyleSwap(currentData, tokenOut, receiver, poolId, balancerVault, cfg) {
347
+ if (cfg === DexPayConfig.FLASH)
348
+ throw new Error("Invalidconfigforv2swap");
349
+ return encodePacked(["bytes", "address", "address", "uint8", "bytes32", "address", "uint8"], [
350
+ currentData,
351
+ tokenOut,
352
+ receiver,
353
+ uint8(DexTypeMappings.BALANCER_V2_ID),
354
+ poolId,
355
+ balancerVault,
356
+ uint8(uint256(cfg)),
357
+ ]);
358
+ }
359
+ export function encodeLbStyleSwap(currentData, tokenOut, receiver, pool, swapForY, cfg) {
360
+ if (cfg === DexPayConfig.FLASH)
361
+ throw new Error("Invalidconfigforv2swap");
362
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8", "uint8"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.LB_ID), pool, uint8(swapForY ? 1 : 0), uint8(uint256(cfg))]);
363
+ }
364
+ export function encodeSyncSwapStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
365
+ if (cfg === DexPayConfig.FLASH)
366
+ throw new Error("Invalidconfigforv2swap");
367
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.SYNC_SWAP_ID), pool, uint8(uint256(cfg))]);
368
+ }
369
+ export function encodeUniswapV3StyleSwap(currentData, tokenOut, receiver, forkId, pool, feeTier, cfg, flashCalldata) {
370
+ if (uint256(cfg) < 2 && flashCalldata.length / 2 - 1 > 2)
371
+ throw new Error("Invalidconfigforv2swap");
372
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8", "uint16", "uint16", "bytes"], [
373
+ currentData,
374
+ tokenOut,
375
+ receiver,
376
+ uint8(DexTypeMappings.UNISWAP_V3_ID),
377
+ pool,
378
+ uint8(forkId),
379
+ uint16(feeTier),
380
+ uint16(cfg === DexPayConfig.FLASH ? flashCalldata.length / 2 - 1 : uint256(cfg)),
381
+ bytes(cfg === DexPayConfig.FLASH ? flashCalldata : newbytes(0)),
382
+ ]);
383
+ }
384
+ export function encodeIzumiStyleSwap(currentData, tokenOut, receiver, forkId, pool, feeTier, cfg, flashCalldata) {
385
+ if (uint256(cfg) < 2 && flashCalldata.length / 2 - 1 > 2)
386
+ throw new Error("Invalidconfigforv2swap");
387
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8", "uint16", "uint16", "bytes"], [
388
+ currentData,
389
+ tokenOut,
390
+ receiver,
391
+ uint8(DexTypeMappings.IZI_ID),
392
+ pool,
393
+ uint8(forkId),
394
+ uint16(feeTier),
395
+ uint16(cfg === DexPayConfig.FLASH ? flashCalldata.length / 2 - 1 : uint256(cfg)),
396
+ bytes(cfg === DexPayConfig.FLASH ? flashCalldata : newbytes(0)),
397
+ ]);
398
+ }
399
+ export function encodeBalancerV3StyleSwap(currentData, tokenOut, receiver, balancerV3Vault, pool, cfg, poolUserData) {
400
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "address", "uint8", "uint16", "bytes"], [
401
+ currentData,
402
+ tokenOut,
403
+ receiver,
404
+ uint8(DexTypeMappings.BALANCER_V3_ID),
405
+ pool,
406
+ balancerV3Vault,
407
+ uint8(cfg),
408
+ uint16(poolUserData.length / 2 - 1),
409
+ poolUserData,
410
+ ]);
411
+ }
412
+ export function encodeDodoStyleSwap(currentData, tokenOut, receiver, pool, selector, poolId, cfg, flashCalldata) {
413
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8", "uint16", "uint16", "bytes"], [
414
+ currentData,
415
+ tokenOut,
416
+ receiver,
417
+ uint8(DexTypeMappings.DODO_ID),
418
+ pool,
419
+ uint8(selector),
420
+ uint16(poolId),
421
+ uint16(cfg === DexPayConfig.FLASH ? flashCalldata.length / 2 - 1 : uint256(cfg)),
422
+ bytes(cfg === DexPayConfig.FLASH ? flashCalldata : newbytes(0)),
423
+ ]);
424
+ }
425
+ export function encodeWooStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
426
+ if (cfg === DexPayConfig.FLASH)
427
+ throw new Error("NoflashforWoo");
428
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.WOO_FI_ID), pool, uint8(uint256(cfg))]);
429
+ }
430
+ export function encodeGmxStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
431
+ if (cfg === DexPayConfig.FLASH)
432
+ throw new Error("NoflashforWoo");
433
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.GMX_ID), pool, uint8(uint256(cfg))]);
434
+ }
435
+ export function encodeKtxStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
436
+ if (cfg === DexPayConfig.FLASH)
437
+ throw new Error("NoflashforWoo");
438
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.KTX_ID), pool, uint8(uint256(cfg))]);
439
+ }
440
+ export function encodeCurveStyleSwap(tokenOut, receiver, pool, indexIn, indexOut, selectorId, cfg) {
441
+ if (cfg === DexPayConfig.FLASH)
442
+ throw new Error("FlashnotyetsupportedforCurve");
443
+ return encodePacked(["address", "address", "uint8", "address", "uint8", "uint8", "uint8", "uint16"], [
444
+ tokenOut,
445
+ receiver,
446
+ uint8(DexTypeMappings.CURVE_V1_STANDARD_ID),
447
+ pool,
448
+ uint8(indexIn),
449
+ uint8(indexOut),
450
+ uint8(selectorId),
451
+ uint16(uint256(cfg)),
452
+ ]);
453
+ }
454
+ export function encodeCurveNGStyleSwap(tokenOut, receiver, pool, indexIn, indexOut, selectorId, cfg) {
455
+ if (cfg === DexPayConfig.FLASH)
456
+ throw new Error("FlashnotyetsupportedforCurve");
457
+ return encodePacked(["address", "address", "uint8", "address", "uint8", "uint8", "uint8", "uint16"], [
458
+ tokenOut,
459
+ receiver,
460
+ uint8(DexTypeMappings.CURVE_RECEIVED_ID),
461
+ pool,
462
+ uint8(indexIn),
463
+ uint8(indexOut),
464
+ uint8(selectorId),
465
+ uint16(uint256(cfg)),
466
+ ]);
467
+ }
468
+ export function encodeWrapperSwap(currentData, assetOut, receiver, operation, cfg) {
469
+ return encodePacked(["bytes", "address", "address", "uint8", "uint8", "uint8"], [
470
+ currentData,
471
+ assetOut,
472
+ receiver,
473
+ uint8(DexTypeMappings.ASSET_WRAP_ID),
474
+ uint8(uint256(operation)),
475
+ uint8(uint256(cfg)),
476
+ ]);
477
+ }
478
+ export function encodeNextGenDexSettle(singleton, nativeAmount) {
479
+ return encodePacked(["uint8", "uint8", "address", "uint128"], [
480
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
481
+ uint8(Gen2025ActionIds.UNI_V4_SETTLE),
482
+ singleton,
483
+ uint128(nativeAmount),
484
+ ]);
485
+ }
486
+ export function encodeNextGenDexSettleBalancer(singleton, asset, amountHint) {
487
+ return encodePacked(["uint8", "uint8", "address", "address", "uint128"], [
488
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
489
+ uint8(Gen2025ActionIds.BAL_V3_SETTLE),
490
+ singleton,
491
+ asset,
492
+ uint128(amountHint >= 0xffffffffffffffffffffffffffffffn ? 0xffffffffffffffffffffffffffffffn : amountHint),
493
+ ]);
494
+ }
495
+ export function encodeTransferIn(asset, receiver, amount) {
496
+ return encodePacked(["uint8", "uint8", "address", "address", "uint128"], [uint8(ComposerCommands.TRANSFERS), uint8(TransferIds.TRANSFER_FROM), asset, receiver, uint128(amount)]);
497
+ }
498
+ export function encodeSweep(asset, receiver, amount, sweepType) {
499
+ return encodePacked(["uint8", "uint8", "address", "address", "uint8", "uint128"], [uint8(ComposerCommands.TRANSFERS), uint8(TransferIds.SWEEP), asset, receiver, sweepType, uint128(amount)]);
500
+ }
501
+ export function encodeWrap(amount, wrapTarget) {
502
+ return encodePacked(["uint8", "uint8", "address", "address", "uint8", "uint128"], [
503
+ uint8(ComposerCommands.TRANSFERS),
504
+ uint8(TransferIds.SWEEP),
505
+ zeroAddress,
506
+ wrapTarget,
507
+ uint8(SweepType.AMOUNT),
508
+ uint128(amount),
509
+ ]);
510
+ }
511
+ export function encodeApprove(asset, target) {
512
+ return encodePacked(["uint8", "uint8", "address", "address"], [uint8(ComposerCommands.TRANSFERS), uint8(TransferIds.APPROVE), asset, target]);
513
+ }
514
+ export function encodeUnwrap(target, receiver, amount, sweepType) {
515
+ return encodePacked(["uint8", "uint8", "address", "address", "uint8", "uint128"], [
516
+ uint8(ComposerCommands.TRANSFERS),
517
+ uint8(TransferIds.UNWRAP_WNATIVE),
518
+ target,
519
+ receiver,
520
+ sweepType,
521
+ uint128(amount),
522
+ ]);
523
+ }
524
+ export function encodeBalancerV2FlashLoan(asset, amount, poolId, data) {
525
+ return encodePacked(["uint8", "uint8", "address", "uint128", "uint16", "bytes"], [
526
+ uint8(ComposerCommands.FLASH_LOAN),
527
+ uint8(FlashLoanIds.BALANCER_V2),
528
+ asset,
529
+ uint128(amount),
530
+ uint16(data.length / 2 - 1 + 1),
531
+ encodeUint8AndBytes(poolId, data),
532
+ ]);
533
+ }
534
+ export function encodeFlashLoan(asset, amount, pool, poolType, poolId, data) {
535
+ return encodePacked(["bytes", "uint8", "uint8", "address", "address", "uint128", "uint16", "bytes"], [
536
+ encodeApprove(asset, pool),
537
+ uint8(ComposerCommands.FLASH_LOAN),
538
+ poolType,
539
+ asset,
540
+ pool,
541
+ uint128(amount),
542
+ uint16(data.length / 2 - 1 + 1),
543
+ encodeUint8AndBytes(poolId, data),
544
+ ]);
545
+ }
546
+ export function encodeUint8AndBytes(poolId, data) {
547
+ return encodePacked(["uint8", "bytes"], [uint8(poolId), data]);
548
+ }
549
+ export function encodeMorphoMarket(loanToken, collateralToken, oracle, irm, lltv) {
550
+ return encodePacked(["address", "address", "address", "address", "uint128"], [loanToken, collateralToken, oracle, irm, uint128(lltv)]);
551
+ }
552
+ export function encodeMorphoDepositCollateral(market, assets, receiver, data, morphoB, pId) {
553
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "bytes", "uint128", "address", "address", "uint16", "bytes"], [
554
+ encodeApprove(getMorphoCollateral(market), morphoB),
555
+ uint8(ComposerCommands.LENDING),
556
+ uint8(LenderOps.DEPOSIT),
557
+ uint16(LenderIds.UP_TO_MORPHO),
558
+ market,
559
+ uint128(assets),
560
+ receiver,
561
+ morphoB,
562
+ uint16(data.length / 2 - 1 > 0 ? data.length / 2 - 1 + 1 : 0),
563
+ data.length / 2 - 1 === 0 ? newbytes(0) : encodeUint8AndBytes(uint8(pId), data),
564
+ ]);
565
+ }
566
+ export function encodeMorphoDeposit(market, isShares, assets, receiver, data, morphoB, pId) {
567
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "bytes", "uint128", "address", "address", "uint16", "bytes"], [
568
+ encodeApprove(getMorphoLoanAsset(market), morphoB),
569
+ uint8(ComposerCommands.LENDING),
570
+ uint8(LenderOps.DEPOSIT_LENDING_TOKEN),
571
+ uint16(LenderIds.UP_TO_MORPHO),
572
+ market,
573
+ generateAmountBitmap(uint128(assets), isShares, false, false),
574
+ receiver,
575
+ morphoB,
576
+ uint16(data.length / 2 - 1 > 0 ? data.length / 2 - 1 + 1 : 0),
577
+ data.length / 2 - 1 === 0 ? newbytes(0) : encodeUint8AndBytes(uint8(pId), data),
578
+ ]);
579
+ }
580
+ export function encodeErc4646Deposit(asset, vault, isShares, assets, receiver) {
581
+ return encodePacked(["bytes", "uint8", "uint8", "address", "address", "uint128", "address"], [
582
+ encodeApprove(asset, vault),
583
+ uint8(ComposerCommands.ERC4626),
584
+ uint8(0),
585
+ asset,
586
+ vault,
587
+ generateAmountBitmap(uint128(assets), isShares, false, false),
588
+ receiver,
589
+ ]);
590
+ }
591
+ export function encodeErc4646Withdraw(vault, isShares, assets, receiver) {
592
+ return encodePacked(["uint8", "uint8", "address", "uint128", "address"], [
593
+ uint8(ComposerCommands.ERC4626),
594
+ uint8(1),
595
+ vault,
596
+ generateAmountBitmap(uint128(assets), isShares, false, false),
597
+ receiver,
598
+ ]);
599
+ }
600
+ export function encodeMorphoWithdraw(market, isShares, assets, receiver, morphoB) {
601
+ return encodePacked(["uint8", "uint8", "uint16", "bytes", "uint128", "address", "address"], [
602
+ uint8(ComposerCommands.LENDING),
603
+ uint8(LenderOps.WITHDRAW_LENDING_TOKEN),
604
+ uint16(LenderIds.UP_TO_MORPHO),
605
+ market,
606
+ generateAmountBitmap(uint128(assets), isShares, false, false),
607
+ receiver,
608
+ morphoB,
609
+ ]);
610
+ }
611
+ export function encodeMorphoWithdrawCollateral(market, assets, receiver, morphoB) {
612
+ return encodePacked(["uint8", "uint8", "uint16", "bytes", "uint128", "address", "address"], [
613
+ uint8(ComposerCommands.LENDING),
614
+ uint8(LenderOps.WITHDRAW),
615
+ uint16(LenderIds.UP_TO_MORPHO),
616
+ market,
617
+ uint128(assets),
618
+ receiver,
619
+ morphoB,
620
+ ]);
621
+ }
622
+ export function encodeMorphoBorrow(market, isShares, assets, receiver, morphoB) {
623
+ return encodePacked(["uint8", "uint8", "uint16", "bytes", "uint128", "address", "address"], [
624
+ uint8(ComposerCommands.LENDING),
625
+ uint8(LenderOps.BORROW),
626
+ uint16(LenderIds.UP_TO_MORPHO),
627
+ market,
628
+ generateAmountBitmap(uint128(assets), isShares, false, false),
629
+ receiver,
630
+ morphoB,
631
+ ]);
632
+ }
633
+ export function encodeMorphoRepay(market, isShares, unsafe, assets, receiver, data, morphoB, pId) {
634
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "bytes", "uint128", "address", "address", "uint16", "bytes"], [
635
+ encodeApprove(getMorphoLoanAsset(market), morphoB),
636
+ uint8(ComposerCommands.LENDING),
637
+ uint8(LenderOps.REPAY),
638
+ uint16(LenderIds.UP_TO_MORPHO),
639
+ market,
640
+ generateAmountBitmap(uint128(assets), isShares, unsafe, false),
641
+ receiver,
642
+ morphoB,
643
+ uint16(data.length / 2 - 1 > 0 ? data.length / 2 - 1 + 1 : 0),
644
+ data.length / 2 - 1 === 0 ? newbytes(0) : encodeUint8AndBytes(uint8(pId), data),
645
+ ]);
646
+ }
647
+ export function encodeAaveDeposit(token, amount, receiver, pool) {
648
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
649
+ encodeApprove(token, pool),
650
+ uint8(ComposerCommands.LENDING),
651
+ uint8(LenderOps.DEPOSIT),
652
+ uint16(LenderIds.UP_TO_AAVE_V3 - 1),
653
+ token,
654
+ uint128(amount),
655
+ receiver,
656
+ pool,
657
+ ]);
658
+ }
659
+ export function encodeAaveBorrow(token, amount, receiver, mode, pool) {
660
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address"], [
661
+ uint8(ComposerCommands.LENDING),
662
+ uint8(LenderOps.BORROW),
663
+ uint16(LenderIds.UP_TO_AAVE_V3 - 1),
664
+ token,
665
+ uint128(amount),
666
+ receiver,
667
+ uint8(mode),
668
+ pool,
669
+ ]);
670
+ }
671
+ export function encodeAaveRepay(token, amount, receiver, mode, dToken, pool) {
672
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address", "address"], [
673
+ encodeApprove(token, pool),
674
+ uint8(ComposerCommands.LENDING),
675
+ uint8(LenderOps.REPAY),
676
+ uint16(LenderIds.UP_TO_AAVE_V3 - 1),
677
+ token,
678
+ uint128(amount),
679
+ receiver,
680
+ uint8(mode),
681
+ dToken,
682
+ pool,
683
+ ]);
684
+ }
685
+ export function encodeAaveWithdraw(token, amount, receiver, aToken, pool) {
686
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address", "address"], [
687
+ uint8(ComposerCommands.LENDING),
688
+ uint8(LenderOps.WITHDRAW),
689
+ uint16(LenderIds.UP_TO_AAVE_V3 - 1),
690
+ token,
691
+ uint128(amount),
692
+ receiver,
693
+ aToken,
694
+ pool,
695
+ ]);
696
+ }
697
+ export function encodeAaveV2Deposit(token, amount, receiver, pool) {
698
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
699
+ encodeApprove(token, pool),
700
+ uint8(ComposerCommands.LENDING),
701
+ uint8(LenderOps.DEPOSIT),
702
+ uint16(LenderIds.UP_TO_AAVE_V2 - 1),
703
+ token,
704
+ uint128(amount),
705
+ receiver,
706
+ pool,
707
+ ]);
708
+ }
709
+ export function encodeAaveV2Borrow(token, amount, receiver, mode, pool) {
710
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address"], [
711
+ uint8(ComposerCommands.LENDING),
712
+ uint8(LenderOps.BORROW),
713
+ uint16(LenderIds.UP_TO_AAVE_V2 - 1),
714
+ token,
715
+ uint128(amount),
716
+ receiver,
717
+ uint8(mode),
718
+ pool,
719
+ ]);
720
+ }
721
+ export function encodeAaveV2Repay(token, amount, receiver, mode, dToken, pool) {
722
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address", "address"], [
723
+ encodeApprove(token, pool),
724
+ uint8(ComposerCommands.LENDING),
725
+ uint8(LenderOps.REPAY),
726
+ uint16(LenderIds.UP_TO_AAVE_V2 - 1),
727
+ token,
728
+ uint128(amount),
729
+ receiver,
730
+ uint8(mode),
731
+ dToken,
732
+ pool,
733
+ ]);
734
+ }
735
+ export function encodeAaveV2Withdraw(token, amount, receiver, aToken, pool) {
736
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address", "address"], [
737
+ uint8(ComposerCommands.LENDING),
738
+ uint8(LenderOps.WITHDRAW),
739
+ uint16(LenderIds.UP_TO_AAVE_V2 - 1),
740
+ token,
741
+ uint128(amount),
742
+ receiver,
743
+ aToken,
744
+ pool,
745
+ ]);
746
+ }
747
+ export function encodeCompoundV3Deposit(token, amount, receiver, comet) {
748
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
749
+ encodeApprove(token, comet),
750
+ uint8(ComposerCommands.LENDING),
751
+ uint8(LenderOps.DEPOSIT),
752
+ uint16(LenderIds.UP_TO_COMPOUND_V3 - 1),
753
+ token,
754
+ uint128(amount),
755
+ receiver,
756
+ comet,
757
+ ]);
758
+ }
759
+ export function encodeCompoundV3Borrow(token, amount, receiver, comet) {
760
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
761
+ uint8(ComposerCommands.LENDING),
762
+ uint8(LenderOps.BORROW),
763
+ uint16(LenderIds.UP_TO_COMPOUND_V3 - 1),
764
+ token,
765
+ uint128(amount),
766
+ receiver,
767
+ comet,
768
+ ]);
769
+ }
770
+ export function encodeCompoundV3Repay(token, amount, receiver, comet) {
771
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
772
+ encodeApprove(token, comet),
773
+ uint8(ComposerCommands.LENDING),
774
+ uint8(LenderOps.REPAY),
775
+ uint16(LenderIds.UP_TO_COMPOUND_V3 - 1),
776
+ token,
777
+ uint128(amount),
778
+ receiver,
779
+ comet,
780
+ ]);
781
+ }
782
+ export function encodeCompoundV3Withdraw(token, amount, receiver, comet, isBase) {
783
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address"], [
784
+ uint8(ComposerCommands.LENDING),
785
+ uint8(LenderOps.WITHDRAW),
786
+ uint16(LenderIds.UP_TO_COMPOUND_V3 - 1),
787
+ token,
788
+ uint128(amount),
789
+ receiver,
790
+ isBase ? uint8(1) : uint8(0),
791
+ comet,
792
+ ]);
793
+ }
794
+ export function encodeCompoundV2Deposit(token, amount, receiver, cToken) {
795
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
796
+ token === zeroAddress ? newbytes(0) : encodeApprove(token, cToken),
797
+ uint8(ComposerCommands.LENDING),
798
+ uint8(LenderOps.DEPOSIT),
799
+ uint16(LenderIds.UP_TO_COMPOUND_V2 - 1),
800
+ token,
801
+ uint128(amount),
802
+ receiver,
803
+ cToken,
804
+ ]);
805
+ }
806
+ export function encodeCompoundV2Borrow(token, amount, receiver, cToken) {
807
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
808
+ uint8(ComposerCommands.LENDING),
809
+ uint8(LenderOps.BORROW),
810
+ uint16(LenderIds.UP_TO_COMPOUND_V2 - 1),
811
+ token,
812
+ uint128(amount),
813
+ receiver,
814
+ cToken,
815
+ ]);
816
+ }
817
+ export function encodeCompoundV2Repay(token, amount, receiver, cToken) {
818
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
819
+ token === zeroAddress ? newbytes(0) : encodeApprove(token, cToken),
820
+ uint8(ComposerCommands.LENDING),
821
+ uint8(LenderOps.REPAY),
822
+ uint16(LenderIds.UP_TO_COMPOUND_V2 - 1),
823
+ token,
824
+ uint128(amount),
825
+ receiver,
826
+ cToken,
827
+ ]);
828
+ }
829
+ export function encodeCompoundV2Withdraw(token, amount, receiver, cToken) {
830
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
831
+ uint8(ComposerCommands.LENDING),
832
+ uint8(LenderOps.WITHDRAW),
833
+ uint16(LenderIds.UP_TO_COMPOUND_V2 - 1),
834
+ token,
835
+ uint128(amount),
836
+ receiver,
837
+ cToken,
838
+ ]);
839
+ }
@@ -0,0 +1,2 @@
1
+ export * from './CalldataLib.js';
2
+ export * from './utils.js';
@@ -0,0 +1,61 @@
1
+ import { encodePacked as abiEncodePacked } from "viem";
2
+ export const _NATIVE_FLAG = 1n << 127n;
3
+ export const _SHARES_MASK = 1n << 126n;
4
+ export const _UNSAFE_AMOUNT = 1n << 125n;
5
+ export function shiftLeft(value, bits) {
6
+ return BigInt(value) << BigInt(bits);
7
+ }
8
+ export function shiftRight(value, bits) {
9
+ return BigInt(value) >> BigInt(bits);
10
+ }
11
+ export function uint8(value) {
12
+ return Number(BigInt(value) & 0xffn);
13
+ }
14
+ export function uint16(value) {
15
+ return Number(BigInt(value) & 0xffffn);
16
+ }
17
+ export function uint32(value) {
18
+ return Number(BigInt(value) & 0xffffffffn);
19
+ }
20
+ export function uint64(value) {
21
+ return BigInt(value) & ((1n << 64n) - 1n);
22
+ }
23
+ export function uint112(value) {
24
+ return BigInt(value) & ((1n << 112n) - 1n);
25
+ }
26
+ export function uint128(value) {
27
+ return BigInt(value) & ((1n << 128n) - 1n);
28
+ }
29
+ export function uint256(value) {
30
+ return BigInt(value) & ((1n << 256n) - 1n);
31
+ }
32
+ export function encodePacked(types, values) {
33
+ if (types.length !== values.length) {
34
+ throw new Error("Types and values arrays must have the same length");
35
+ }
36
+ return abiEncodePacked(types, values);
37
+ }
38
+ export function generateAmountBitmap(amount, useShares, unsafe, native) {
39
+ let am = amount;
40
+ if (useShares)
41
+ am = uint128((am & ~BigInt(_SHARES_MASK)) | _SHARES_MASK);
42
+ if (unsafe)
43
+ am = uint128((am & ~BigInt(_UNSAFE_AMOUNT)) | _UNSAFE_AMOUNT);
44
+ if (native)
45
+ am = uint128((am & ~BigInt(_NATIVE_FLAG)) | _NATIVE_FLAG);
46
+ return am;
47
+ }
48
+ export function getMorphoCollateral(market) {
49
+ const slice = market.slice(42, 82);
50
+ return `0x${slice}`;
51
+ }
52
+ export function getMorphoLoanAsset(market) {
53
+ const slice = market.slice(2, 42);
54
+ return `0x${slice}`;
55
+ }
56
+ export function newbytes(length) {
57
+ return ("0x" + "0".repeat(length * 2));
58
+ }
59
+ export function bytes(value) {
60
+ return value;
61
+ }
@@ -0,0 +1,180 @@
1
+ import { type Hex, type Address } from "viem";
2
+ export declare enum SweepType {
3
+ VALIDATE = 0,
4
+ AMOUNT = 1
5
+ }
6
+ export declare enum DexPayConfig {
7
+ CALLER_PAYS = 0,
8
+ CONTRACT_PAYS = 1,
9
+ PRE_FUND = 2,
10
+ FLASH = 3
11
+ }
12
+ export declare enum DodoSelector {
13
+ SELL_BASE = 0,
14
+ SELL_QUOTE = 1
15
+ }
16
+ export declare enum WrapOperation {
17
+ NATIVE = 0,
18
+ ERC4626_DEPOSIT = 1,
19
+ ERC4626_REDEEM = 2
20
+ }
21
+ export declare enum TransferIds {
22
+ TRANSFER_FROM = 0,
23
+ SWEEP = 1,
24
+ WRAP_NATIVE = 2,
25
+ UNWRAP_WNATIVE = 3,
26
+ PERMIT2_TRANSFER_FROM = 4,
27
+ APPROVE = 5
28
+ }
29
+ export declare enum PermitIds {
30
+ TOKEN_PERMIT = 0,
31
+ AAVE_V3_CREDIT_PERMIT = 1,
32
+ ALLOW_CREDIT_PERMIT = 2
33
+ }
34
+ export declare enum LenderIds {
35
+ UP_TO_AAVE_V3 = 1000,
36
+ UP_TO_AAVE_V2 = 2000,
37
+ UP_TO_COMPOUND_V3 = 3000,
38
+ UP_TO_COMPOUND_V2 = 4000,
39
+ UP_TO_MORPHO = 5000
40
+ }
41
+ export declare enum LenderOps {
42
+ DEPOSIT = 0,
43
+ BORROW = 1,
44
+ REPAY = 2,
45
+ WITHDRAW = 3,
46
+ DEPOSIT_LENDING_TOKEN = 4,
47
+ WITHDRAW_LENDING_TOKEN = 5
48
+ }
49
+ export declare enum FlashLoanIds {
50
+ MORPHO = 0,
51
+ BALANCER_V2 = 1,
52
+ AAVE_V3 = 2,
53
+ AAVE_V2 = 3
54
+ }
55
+ export declare enum ERC4626Ids {
56
+ DEPOSIT = 0,
57
+ WITHDRAW = 1
58
+ }
59
+ export declare enum Gen2025ActionIds {
60
+ UNLOCK = 0,
61
+ UNI_V4_TAKE = 1,
62
+ UNI_V4_SETTLE = 2,
63
+ UNI_V4_SYNC = 3,
64
+ BAL_V3_TAKE = 4,
65
+ BAL_V3_SETTLE = 5
66
+ }
67
+ export declare enum ComposerCommands {
68
+ SWAPS = 16,
69
+ EXT_CALL = 32,
70
+ EXT_TRY_CALL = 33,
71
+ LENDING = 48,
72
+ TRANSFERS = 64,
73
+ PERMIT = 80,
74
+ FLASH_LOAN = 96,
75
+ ERC4626 = 112,
76
+ GEN_2025_SINGELTONS = 128,
77
+ BRIDGING = 144
78
+ }
79
+ export declare enum BridgeIds {
80
+ STARGATE_V2 = 0,
81
+ ACROSS = 10
82
+ }
83
+ export declare enum DexTypeMappings {
84
+ UNISWAP_V3_ID = 0,
85
+ UNISWAP_V2_ID = 1,
86
+ UNISWAP_V4_ID = 2,
87
+ IZI_ID = 5,
88
+ UNISWAP_V2_FOT_ID = 3,
89
+ CURVE_V1_STANDARD_ID = 64,
90
+ CURVE_RECEIVED_ID = 65,
91
+ CURVE_FORK_ID = 66,
92
+ WOO_FI_ID = 80,
93
+ GMX_ID = 90,
94
+ KTX_ID = 91,
95
+ BALANCER_V2_ID = 128,
96
+ BALANCER_V3_ID = 129,
97
+ LB_ID = 140,
98
+ DODO_ID = 150,
99
+ SYNC_SWAP_ID = 160,
100
+ ERC4626_ID = 253,
101
+ ASSET_WRAP_ID = 254
102
+ }
103
+ export declare enum DexForkMappings {
104
+ UNISWAP_V3 = 0,
105
+ IZI = 0,
106
+ ANY_V3 = 255,
107
+ ANY_IZI = 255,
108
+ UNISWAP_V4 = 0,
109
+ BALANCER_V3 = 0,
110
+ UNISWAP_V2 = 0
111
+ }
112
+ export declare function encodeExternalCall(target: Address, value: bigint, useSelfBalance: boolean, data: Hex): Hex;
113
+ export declare function encodeTryExternalCall(target: Address, value: bigint, useSelfBalance: boolean, rOnFailure: boolean, data: Hex, catchData: Hex): Hex;
114
+ export declare function encodeStargateV2Bridge(asset: Address, stargatePool: Address, dstEid: number, receiver: Hex, refundReceiver: Address, amount: bigint, slippage: number, fee: bigint, isBusMode: boolean, isNative: boolean, composeMsg: Hex, extraOptions: Hex): Hex;
115
+ export declare function encodeStargateV2BridgePartial(amount: bigint, slippage: number, fee: bigint, isBusMode: boolean, isNative: boolean, composeMsg: Hex, extraOptions: Hex): Hex;
116
+ export declare function encodeStargateV2BridgeSimpleTaxi(asset: Address, stargatePool: Address, dstEid: number, receiver: Hex, refundReceiver: Address, amount: bigint, isNative: boolean, slippage: number, fee: bigint): Hex;
117
+ export declare function encodeStargateV2BridgeSimpleBus(asset: Address, stargatePool: Address, dstEid: number, receiver: Hex, refundReceiver: Address, amount: bigint, isNative: boolean, slippage: number, fee: bigint): Hex;
118
+ export declare function encodeAcrossBridgeToken(spokePool: Address, depositor: Address, sendingAssetId: Address, receivingAssetId: Address, amount: bigint, fixedFee: bigint, feePercentage: number, destinationChainId: number, receiver: Address, message: Hex): Hex;
119
+ export declare function encodeAcrossBridgeNative(spokePool: Address, depositor: Address, sendingAssetId: Address, receivingAssetId: Address, amount: bigint, fixedFee: bigint, feePercentage: number, destinationChainId: number, receiver: Address, message: Hex): Hex;
120
+ export declare function encodePermit2TransferFrom(token: Address, receiver: Address, amount: bigint): Hex;
121
+ export declare function encodeNextGenDexUnlock(singleton: Address, id: bigint, d: Hex): Hex;
122
+ export declare function encodeBalancerV3FlashLoan(singleton: Address, poolId: bigint, asset: Address, receiver: Address, amount: bigint, flashData: Hex): Hex;
123
+ export declare function encodeBalancerV3FlashLoanData(take: Hex, flashData: Hex, settle: Hex): Hex;
124
+ export declare function encodeUniswapV4FlashLoan(singleton: Address, poolId: bigint, asset: Address, receiver: Address, amount: bigint, flashData: Hex): Hex;
125
+ export declare function encodeUniswapV4FlashLoanData(take: Hex, sync: Hex, flashData: Hex, settle: Hex): Hex;
126
+ export declare function encodeBalancerV3Take(singleton: Address, asset: Address, receiver: Address, amount: bigint): Hex;
127
+ export declare function encodeUniswapV4Sync(singleton: Address, asset: Address): Hex;
128
+ export declare function encodeUniswapV4Take(singleton: Address, asset: Address, receiver: Address, amount: bigint): Hex;
129
+ export declare function swapHead(amount: bigint, amountOutMin: bigint, assetIn: Address): Hex;
130
+ export declare function attachBranch(data: Hex, hops: bigint, splits: bigint, splitsData: Hex): Hex;
131
+ export declare function encodeUniswapV2StyleSwap(tokenOut: Address, receiver: Address, forkId: bigint, pool: Address, feeDenom: bigint, cfg: any, flashCalldata: Hex): Hex;
132
+ export declare function encodeUniswapV4StyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, manager: Address, fee: number, tickSpacing: number, hooks: Address, hookData: Hex, cfg: any): Hex;
133
+ export declare function encodeBalancerV2StyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, poolId: Hex, balancerVault: Address, cfg: any): Hex;
134
+ export declare function encodeLbStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, swapForY: boolean, cfg: any): Hex;
135
+ export declare function encodeSyncSwapStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, cfg: any): Hex;
136
+ export declare function encodeUniswapV3StyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, forkId: bigint, pool: Address, feeTier: bigint, cfg: any, flashCalldata: Hex): Hex;
137
+ export declare function encodeIzumiStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, forkId: bigint, pool: Address, feeTier: bigint, cfg: any, flashCalldata: Hex): Hex;
138
+ export declare function encodeBalancerV3StyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, balancerV3Vault: Address, pool: Address, cfg: any, poolUserData: Hex): Hex;
139
+ export declare function encodeDodoStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, selector: any, poolId: bigint, cfg: any, flashCalldata: Hex): Hex;
140
+ export declare function encodeWooStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, cfg: any): Hex;
141
+ export declare function encodeGmxStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, cfg: any): Hex;
142
+ export declare function encodeKtxStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, cfg: any): Hex;
143
+ export declare function encodeCurveStyleSwap(tokenOut: Address, receiver: Address, pool: Address, indexIn: bigint, indexOut: bigint, selectorId: bigint, cfg: any): Hex;
144
+ export declare function encodeCurveNGStyleSwap(tokenOut: Address, receiver: Address, pool: Address, indexIn: bigint, indexOut: bigint, selectorId: bigint, cfg: any): Hex;
145
+ export declare function encodeWrapperSwap(currentData: Hex, assetOut: Address, receiver: Address, operation: any, cfg: any): Hex;
146
+ export declare function encodeNextGenDexSettle(singleton: Address, nativeAmount: bigint): Hex;
147
+ export declare function encodeNextGenDexSettleBalancer(singleton: Address, asset: Address, amountHint: bigint): Hex;
148
+ export declare function encodeTransferIn(asset: Address, receiver: Address, amount: bigint): Hex;
149
+ export declare function encodeSweep(asset: Address, receiver: Address, amount: bigint, sweepType: any): Hex;
150
+ export declare function encodeWrap(amount: bigint, wrapTarget: Address): Hex;
151
+ export declare function encodeApprove(asset: Address, target: Address): Hex;
152
+ export declare function encodeUnwrap(target: Address, receiver: Address, amount: bigint, sweepType: any): Hex;
153
+ export declare function encodeBalancerV2FlashLoan(asset: Address, amount: bigint, poolId: number, data: Hex): Hex;
154
+ export declare function encodeFlashLoan(asset: Address, amount: bigint, pool: Address, poolType: number, poolId: number, data: Hex): Hex;
155
+ export declare function encodeUint8AndBytes(poolId: number, data: Hex): Hex;
156
+ export declare function encodeMorphoMarket(loanToken: Address, collateralToken: Address, oracle: Address, irm: Address, lltv: bigint): Hex;
157
+ export declare function encodeMorphoDepositCollateral(market: Hex, assets: bigint, receiver: Address, data: Hex, morphoB: Address, pId: bigint): Hex;
158
+ export declare function encodeMorphoDeposit(market: Hex, isShares: boolean, assets: bigint, receiver: Address, data: Hex, morphoB: Address, pId: bigint): Hex;
159
+ export declare function encodeErc4646Deposit(asset: Address, vault: Address, isShares: boolean, assets: bigint, receiver: Address): Hex;
160
+ export declare function encodeErc4646Withdraw(vault: Address, isShares: boolean, assets: bigint, receiver: Address): Hex;
161
+ export declare function encodeMorphoWithdraw(market: Hex, isShares: boolean, assets: bigint, receiver: Address, morphoB: Address): Hex;
162
+ export declare function encodeMorphoWithdrawCollateral(market: Hex, assets: bigint, receiver: Address, morphoB: Address): Hex;
163
+ export declare function encodeMorphoBorrow(market: Hex, isShares: boolean, assets: bigint, receiver: Address, morphoB: Address): Hex;
164
+ export declare function encodeMorphoRepay(market: Hex, isShares: boolean, unsafe: boolean, assets: bigint, receiver: Address, data: Hex, morphoB: Address, pId: bigint): Hex;
165
+ export declare function encodeAaveDeposit(token: Address, amount: bigint, receiver: Address, pool: Address): Hex;
166
+ export declare function encodeAaveBorrow(token: Address, amount: bigint, receiver: Address, mode: bigint, pool: Address): Hex;
167
+ export declare function encodeAaveRepay(token: Address, amount: bigint, receiver: Address, mode: bigint, dToken: Address, pool: Address): Hex;
168
+ export declare function encodeAaveWithdraw(token: Address, amount: bigint, receiver: Address, aToken: Address, pool: Address): Hex;
169
+ export declare function encodeAaveV2Deposit(token: Address, amount: bigint, receiver: Address, pool: Address): Hex;
170
+ export declare function encodeAaveV2Borrow(token: Address, amount: bigint, receiver: Address, mode: bigint, pool: Address): Hex;
171
+ export declare function encodeAaveV2Repay(token: Address, amount: bigint, receiver: Address, mode: bigint, dToken: Address, pool: Address): Hex;
172
+ export declare function encodeAaveV2Withdraw(token: Address, amount: bigint, receiver: Address, aToken: Address, pool: Address): Hex;
173
+ export declare function encodeCompoundV3Deposit(token: Address, amount: bigint, receiver: Address, comet: Address): Hex;
174
+ export declare function encodeCompoundV3Borrow(token: Address, amount: bigint, receiver: Address, comet: Address): Hex;
175
+ export declare function encodeCompoundV3Repay(token: Address, amount: bigint, receiver: Address, comet: Address): Hex;
176
+ export declare function encodeCompoundV3Withdraw(token: Address, amount: bigint, receiver: Address, comet: Address, isBase: boolean): Hex;
177
+ export declare function encodeCompoundV2Deposit(token: Address, amount: bigint, receiver: Address, cToken: Address): Hex;
178
+ export declare function encodeCompoundV2Borrow(token: Address, amount: bigint, receiver: Address, cToken: Address): Hex;
179
+ export declare function encodeCompoundV2Repay(token: Address, amount: bigint, receiver: Address, cToken: Address): Hex;
180
+ export declare function encodeCompoundV2Withdraw(token: Address, amount: bigint, receiver: Address, cToken: Address): Hex;
@@ -0,0 +1,2 @@
1
+ export * from './CalldataLib.js';
2
+ export * from './utils.js';
@@ -0,0 +1,19 @@
1
+ import { type Hex, type Address } from "viem";
2
+ export declare const _NATIVE_FLAG: bigint;
3
+ export declare const _SHARES_MASK: bigint;
4
+ export declare const _UNSAFE_AMOUNT: bigint;
5
+ export declare function shiftLeft(value: bigint | number, bits: number): bigint;
6
+ export declare function shiftRight(value: bigint | number, bits: number): bigint;
7
+ export declare function uint8(value: number | bigint): number;
8
+ export declare function uint16(value: number | bigint): number;
9
+ export declare function uint32(value: number | bigint): number;
10
+ export declare function uint64(value: number | bigint): bigint;
11
+ export declare function uint112(value: number | bigint): bigint;
12
+ export declare function uint128(value: number | bigint): bigint;
13
+ export declare function uint256(value: number | bigint): bigint;
14
+ export declare function encodePacked(types: string[], values: any[]): Hex;
15
+ export declare function generateAmountBitmap(amount: bigint, useShares: boolean, unsafe: boolean, native: boolean): bigint;
16
+ export declare function getMorphoCollateral(market: Hex): Address;
17
+ export declare function getMorphoLoanAsset(market: Hex): Address;
18
+ export declare function newbytes(length: number): Hex;
19
+ export declare function bytes(value: Hex): Hex;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@1delta/calldatalib",
3
- "version": "0.0.27",
3
+ "version": "0.0.30",
4
4
  "description": "Generated CalldataLib TypeScript functions for 1delta smart contracts",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
7
+ "module": "./dist/esm/index.js",
8
+ "types": "./dist/types/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "import": "./dist/index.js",
11
+ "import": "./dist/esm/index.js",
12
12
  "require": "./dist/cjs/index.js",
13
13
  "types": "./dist/index.d.ts"
14
14
  }
@@ -30,6 +30,8 @@
30
30
  "viem": "^2.0.0"
31
31
  },
32
32
  "scripts": {
33
- "build": "tsc && tsc -p tsconfig.cjs.json"
33
+ "build": "npm run build:esm && npm run build:cjs",
34
+ "build:esm": "tsc --project tsconfig.json --outDir dist/esm --module ESNext",
35
+ "build:cjs": "tsc --project tsconfig.json --outDir dist/cjs --module CommonJS"
34
36
  }
35
37
  }