@1delta/calldatalib 0.0.21 → 0.0.23

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