@1delta/calldatalib 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,166 @@
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 TransferIds {
17
+ TRANSFER_FROM = 0,
18
+ SWEEP = 1,
19
+ WRAP_NATIVE = 2,
20
+ UNWRAP_WNATIVE = 3,
21
+ PERMIT2_TRANSFER_FROM = 4,
22
+ APPROVE = 5
23
+ }
24
+ export declare enum PermitIds {
25
+ TOKEN_PERMIT = 0,
26
+ AAVE_V3_CREDIT_PERMIT = 1,
27
+ ALLOW_CREDIT_PERMIT = 2
28
+ }
29
+ export declare enum LenderIds {
30
+ UP_TO_AAVE_V3 = 1000,
31
+ UP_TO_AAVE_V2 = 2000,
32
+ UP_TO_COMPOUND_V3 = 3000,
33
+ UP_TO_COMPOUND_V2 = 4000,
34
+ UP_TO_MORPHO = 5000
35
+ }
36
+ export declare enum LenderOps {
37
+ DEPOSIT = 0,
38
+ BORROW = 1,
39
+ REPAY = 2,
40
+ WITHDRAW = 3,
41
+ DEPOSIT_LENDING_TOKEN = 4,
42
+ WITHDRAW_LENDING_TOKEN = 5
43
+ }
44
+ export declare enum FlashLoanIds {
45
+ MORPHO = 0,
46
+ BALANCER_V2 = 1,
47
+ AAVE_V3 = 2,
48
+ AAVE_V2 = 3
49
+ }
50
+ export declare enum ERC4646Ids {
51
+ DEPOSIT = 0,
52
+ WITHDRAW = 1
53
+ }
54
+ export declare enum Gen2025ActionIds {
55
+ UNLOCK = 0,
56
+ UNI_V4_TAKE = 1,
57
+ UNI_V4_SETTLE = 2,
58
+ UNI_V4_SYNC = 3,
59
+ BAL_V3_TAKE = 4,
60
+ BAL_V3_SETTLE = 5
61
+ }
62
+ export declare enum ComposerCommands {
63
+ SWAPS = 32,
64
+ EXT_CALL = 64,
65
+ LENDING = 96,
66
+ TRANSFERS = 128,
67
+ PERMIT = 160,
68
+ FLASH_LOAN = 192,
69
+ ERC4646 = 224,
70
+ GEN_2025_SINGELTONS = 225
71
+ }
72
+ export declare enum ForwarderCommands {
73
+ EXT_CALL = 64,
74
+ ASSET_HANDLING = 128
75
+ }
76
+ export declare enum DexTypeMappings {
77
+ UNISWAP_V3_ID = 0,
78
+ IZI_ID = 1,
79
+ UNISWAP_V4_ID = 2,
80
+ BALANCER_V3_ID = 4,
81
+ BALANCER_V2_ID = 3,
82
+ UNISWAP_V2_ID = 6,
83
+ UNISWAP_V2_FOT_ID = 7,
84
+ CURVE_V1_STANDARD_ID = 60,
85
+ CURVE_FORK_ID = 61,
86
+ UNISWAP_V2_MAX_ID = 150,
87
+ CURVE_RECEIVED_ID = 150,
88
+ WOO_FI_ID = 155,
89
+ LB_ID = 160,
90
+ GMX_ID = 170,
91
+ KTX_ID = 171,
92
+ MAX_GMX_ID = 173,
93
+ DODO_ID = 180,
94
+ SYNC_SWAP_ID = 190,
95
+ NATIVE_WRAP_ID = 254
96
+ }
97
+ export declare enum DexForkMappings {
98
+ UNISWAP_V3 = 0,
99
+ IZI = 0,
100
+ ANY_V3 = 255,
101
+ ANY_IZI = 255,
102
+ UNISWAP_V4 = 0,
103
+ BALANCER_V3 = 0,
104
+ UNISWAP_V2 = 0
105
+ }
106
+ export declare function encodePermit2TransferFrom(token: Address, receiver: Address, amount: bigint): Hex;
107
+ export declare function encodeNextGenDexUnlock(singleton: Address, id: bigint, d: Hex): Hex;
108
+ export declare function encodeBalancerV3FlashLoan(singleton: Address, poolId: bigint, asset: Address, receiver: Address, amount: bigint, flashData: Hex): Hex;
109
+ export declare function encodeBalancerV3FlashLoanData(take: Hex, flashData: Hex, settle: Hex): Hex;
110
+ export declare function encodeUniswapV4FlashLoan(singleton: Address, poolId: bigint, asset: Address, receiver: Address, amount: bigint, flashData: Hex): Hex;
111
+ export declare function encodeUniswapV4FlashLoanData(take: Hex, sync: Hex, flashData: Hex, settle: Hex): Hex;
112
+ export declare function encodeBalancerV3Take(singleton: Address, asset: Address, receiver: Address, amount: bigint): Hex;
113
+ export declare function encodeUniswapV4Sync(singleton: Address, asset: Address): Hex;
114
+ export declare function encodeUniswapV4Take(singleton: Address, asset: Address, receiver: Address, amount: bigint): Hex;
115
+ export declare function swapHead(amount: bigint, amountOutMin: bigint, assetIn: Address): Hex;
116
+ export declare function attachBranch(data: Hex, hops: bigint, splits: bigint, splitsData: Hex): Hex;
117
+ export declare function uniswapV2StyleSwap(tokenOut: Address, receiver: Address, forkId: bigint, pool: Address, feeDenom: bigint, cfg: any, flashCalldata: Hex): Hex;
118
+ export declare function uniswapV4StyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, manager: Address, fee: number, tickSpacing: number, hooks: Address, hookData: Hex, cfg: any): Hex;
119
+ export declare function balancerV2StyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, poolId: Hex, balancerVault: Address, cfg: any): Hex;
120
+ export declare function lbStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, swapForY: boolean, cfg: any): Hex;
121
+ export declare function syncSwapStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, cfg: any): Hex;
122
+ export declare function uniswapV3StyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, forkId: bigint, pool: Address, feeTier: bigint, cfg: any, flashCalldata: Hex): Hex;
123
+ export declare function izumiV3StyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, forkId: bigint, pool: Address, feeTier: bigint, cfg: any, flashCalldata: Hex): Hex;
124
+ export declare function balancerV3StyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, balancerV3Vault: Address, pool: Address, cfg: any, poolUserData: Hex): Hex;
125
+ export declare function encodeIzumiStyleSwap(tokenOut: Address, receiver: Address, forkId: bigint, pool: Address, feeTier: bigint, cfg: any, flashCalldata: Hex): Hex;
126
+ export declare function encodeDodoStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, selector: any, poolId: bigint, cfg: any, flashCalldata: Hex): Hex;
127
+ export declare function encodeWooStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, cfg: any): Hex;
128
+ export declare function encodeGmxStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, cfg: any): Hex;
129
+ export declare function encodeKtxStyleSwap(currentData: Hex, tokenOut: Address, receiver: Address, pool: Address, cfg: any): Hex;
130
+ export declare function encodeCurveStyleSwap(tokenOut: Address, receiver: Address, pool: Address, indexIn: bigint, indexOut: bigint, selectorId: bigint, cfg: any): Hex;
131
+ export declare function encodeCurveNGStyleSwap(tokenOut: Address, receiver: Address, pool: Address, indexIn: bigint, indexOut: bigint, selectorId: bigint, cfg: any): Hex;
132
+ export declare function encodeNextGenDexSettle(singleton: Address, nativeAmount: bigint): Hex;
133
+ export declare function encodeNextGenDexSettleBalancer(singleton: Address, asset: Address, amountHint: bigint): Hex;
134
+ export declare function encodeTransferIn(asset: Address, receiver: Address, amount: bigint): Hex;
135
+ export declare function encodeSweep(asset: Address, receiver: Address, amount: bigint, sweepType: any): Hex;
136
+ export declare function encodeWrap(amount: bigint, wrapTarget: Address): Hex;
137
+ export declare function encodeApprove(asset: Address, target: Address): Hex;
138
+ export declare function encodeUnwrap(target: Address, receiver: Address, amount: bigint, sweepType: any): Hex;
139
+ export declare function encodeBalancerV2FlashLoan(asset: Address, amount: bigint, poolId: number, data: Hex): Hex;
140
+ export declare function encodeFlashLoan(asset: Address, amount: bigint, pool: Address, poolType: number, poolId: number, data: Hex): Hex;
141
+ export declare function encodeUint8AndBytes(poolId: number, data: Hex): Hex;
142
+ export declare function encodeMorphoMarket(loanToken: Address, collateralToken: Address, oracle: Address, irm: Address, lltv: bigint): Hex;
143
+ export declare function encodeMorphoDepositCollateral(market: Hex, assets: bigint, receiver: Address, data: Hex, morphoB: Address, pId: bigint): Hex;
144
+ export declare function encodeMorphoDeposit(market: Hex, isShares: boolean, assets: bigint, receiver: Address, data: Hex, morphoB: Address, pId: bigint): Hex;
145
+ export declare function encodeErc4646Deposit(asset: Address, vault: Address, isShares: boolean, assets: bigint, receiver: Address): Hex;
146
+ export declare function encodeErc4646Withdraw(vault: Address, isShares: boolean, assets: bigint, receiver: Address): Hex;
147
+ export declare function encodeMorphoWithdraw(market: Hex, isShares: boolean, assets: bigint, receiver: Address, morphoB: Address): Hex;
148
+ export declare function encodeMorphoWithdrawCollateral(market: Hex, assets: bigint, receiver: Address, morphoB: Address): Hex;
149
+ export declare function encodeMorphoBorrow(market: Hex, isShares: boolean, assets: bigint, receiver: Address, morphoB: Address): Hex;
150
+ export declare function encodeMorphoRepay(market: Hex, isShares: boolean, unsafe: boolean, assets: bigint, receiver: Address, data: Hex, morphoB: Address, pId: bigint): Hex;
151
+ export declare function encodeAaveDeposit(token: Address, amount: bigint, receiver: Address, pool: Address): Hex;
152
+ export declare function encodeAaveBorrow(token: Address, amount: bigint, receiver: Address, mode: bigint, pool: Address): Hex;
153
+ export declare function encodeAaveRepay(token: Address, amount: bigint, receiver: Address, mode: bigint, dToken: Address, pool: Address): Hex;
154
+ export declare function encodeAaveWithdraw(token: Address, amount: bigint, receiver: Address, aToken: Address, pool: Address): Hex;
155
+ export declare function encodeAaveV2Deposit(token: Address, amount: bigint, receiver: Address, pool: Address): Hex;
156
+ export declare function encodeAaveV2Borrow(token: Address, amount: bigint, receiver: Address, mode: bigint, pool: Address): Hex;
157
+ export declare function encodeAaveV2Repay(token: Address, amount: bigint, receiver: Address, mode: bigint, dToken: Address, pool: Address): Hex;
158
+ export declare function encodeAaveV2Withdraw(token: Address, amount: bigint, receiver: Address, aToken: Address, pool: Address): Hex;
159
+ export declare function encodeCompoundV3Deposit(token: Address, amount: bigint, receiver: Address, comet: Address): Hex;
160
+ export declare function encodeCompoundV3Borrow(token: Address, amount: bigint, receiver: Address, comet: Address): Hex;
161
+ export declare function encodeCompoundV3Repay(token: Address, amount: bigint, receiver: Address, comet: Address): Hex;
162
+ export declare function encodeCompoundV3Withdraw(token: Address, amount: bigint, receiver: Address, comet: Address, isBase: boolean): Hex;
163
+ export declare function encodeCompoundV2Deposit(token: Address, amount: bigint, receiver: Address, cToken: Address): Hex;
164
+ export declare function encodeCompoundV2Borrow(token: Address, amount: bigint, receiver: Address, cToken: Address): Hex;
165
+ export declare function encodeCompoundV2Repay(token: Address, amount: bigint, receiver: Address, cToken: Address): Hex;
166
+ export declare function encodeCompoundV2Withdraw(token: Address, amount: bigint, receiver: Address, cToken: Address): Hex;
@@ -0,0 +1,728 @@
1
+ // @ts-nocheck
2
+ import { zeroAddress } from "viem";
3
+ import { encodePacked, uint128, uint8, uint16, uint256, generateAmountBitmap, newbytes, bytes, getMorphoCollateral, getMorphoLoanAsset, } from "./utils";
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 TransferIds;
22
+ (function (TransferIds) {
23
+ TransferIds[TransferIds["TRANSFER_FROM"] = 0] = "TRANSFER_FROM";
24
+ TransferIds[TransferIds["SWEEP"] = 1] = "SWEEP";
25
+ TransferIds[TransferIds["WRAP_NATIVE"] = 2] = "WRAP_NATIVE";
26
+ TransferIds[TransferIds["UNWRAP_WNATIVE"] = 3] = "UNWRAP_WNATIVE";
27
+ TransferIds[TransferIds["PERMIT2_TRANSFER_FROM"] = 4] = "PERMIT2_TRANSFER_FROM";
28
+ TransferIds[TransferIds["APPROVE"] = 5] = "APPROVE";
29
+ })(TransferIds || (TransferIds = {}));
30
+ export var PermitIds;
31
+ (function (PermitIds) {
32
+ PermitIds[PermitIds["TOKEN_PERMIT"] = 0] = "TOKEN_PERMIT";
33
+ PermitIds[PermitIds["AAVE_V3_CREDIT_PERMIT"] = 1] = "AAVE_V3_CREDIT_PERMIT";
34
+ PermitIds[PermitIds["ALLOW_CREDIT_PERMIT"] = 2] = "ALLOW_CREDIT_PERMIT";
35
+ })(PermitIds || (PermitIds = {}));
36
+ export var LenderIds;
37
+ (function (LenderIds) {
38
+ LenderIds[LenderIds["UP_TO_AAVE_V3"] = 1000] = "UP_TO_AAVE_V3";
39
+ LenderIds[LenderIds["UP_TO_AAVE_V2"] = 2000] = "UP_TO_AAVE_V2";
40
+ LenderIds[LenderIds["UP_TO_COMPOUND_V3"] = 3000] = "UP_TO_COMPOUND_V3";
41
+ LenderIds[LenderIds["UP_TO_COMPOUND_V2"] = 4000] = "UP_TO_COMPOUND_V2";
42
+ LenderIds[LenderIds["UP_TO_MORPHO"] = 5000] = "UP_TO_MORPHO";
43
+ })(LenderIds || (LenderIds = {}));
44
+ export var LenderOps;
45
+ (function (LenderOps) {
46
+ LenderOps[LenderOps["DEPOSIT"] = 0] = "DEPOSIT";
47
+ LenderOps[LenderOps["BORROW"] = 1] = "BORROW";
48
+ LenderOps[LenderOps["REPAY"] = 2] = "REPAY";
49
+ LenderOps[LenderOps["WITHDRAW"] = 3] = "WITHDRAW";
50
+ LenderOps[LenderOps["DEPOSIT_LENDING_TOKEN"] = 4] = "DEPOSIT_LENDING_TOKEN";
51
+ LenderOps[LenderOps["WITHDRAW_LENDING_TOKEN"] = 5] = "WITHDRAW_LENDING_TOKEN";
52
+ })(LenderOps || (LenderOps = {}));
53
+ export var FlashLoanIds;
54
+ (function (FlashLoanIds) {
55
+ FlashLoanIds[FlashLoanIds["MORPHO"] = 0] = "MORPHO";
56
+ FlashLoanIds[FlashLoanIds["BALANCER_V2"] = 1] = "BALANCER_V2";
57
+ FlashLoanIds[FlashLoanIds["AAVE_V3"] = 2] = "AAVE_V3";
58
+ FlashLoanIds[FlashLoanIds["AAVE_V2"] = 3] = "AAVE_V2";
59
+ })(FlashLoanIds || (FlashLoanIds = {}));
60
+ export var ERC4646Ids;
61
+ (function (ERC4646Ids) {
62
+ ERC4646Ids[ERC4646Ids["DEPOSIT"] = 0] = "DEPOSIT";
63
+ ERC4646Ids[ERC4646Ids["WITHDRAW"] = 1] = "WITHDRAW";
64
+ })(ERC4646Ids || (ERC4646Ids = {}));
65
+ export var Gen2025ActionIds;
66
+ (function (Gen2025ActionIds) {
67
+ Gen2025ActionIds[Gen2025ActionIds["UNLOCK"] = 0] = "UNLOCK";
68
+ Gen2025ActionIds[Gen2025ActionIds["UNI_V4_TAKE"] = 1] = "UNI_V4_TAKE";
69
+ Gen2025ActionIds[Gen2025ActionIds["UNI_V4_SETTLE"] = 2] = "UNI_V4_SETTLE";
70
+ Gen2025ActionIds[Gen2025ActionIds["UNI_V4_SYNC"] = 3] = "UNI_V4_SYNC";
71
+ Gen2025ActionIds[Gen2025ActionIds["BAL_V3_TAKE"] = 4] = "BAL_V3_TAKE";
72
+ Gen2025ActionIds[Gen2025ActionIds["BAL_V3_SETTLE"] = 5] = "BAL_V3_SETTLE";
73
+ })(Gen2025ActionIds || (Gen2025ActionIds = {}));
74
+ export var ComposerCommands;
75
+ (function (ComposerCommands) {
76
+ ComposerCommands[ComposerCommands["SWAPS"] = 32] = "SWAPS";
77
+ ComposerCommands[ComposerCommands["EXT_CALL"] = 64] = "EXT_CALL";
78
+ ComposerCommands[ComposerCommands["LENDING"] = 96] = "LENDING";
79
+ ComposerCommands[ComposerCommands["TRANSFERS"] = 128] = "TRANSFERS";
80
+ ComposerCommands[ComposerCommands["PERMIT"] = 160] = "PERMIT";
81
+ ComposerCommands[ComposerCommands["FLASH_LOAN"] = 192] = "FLASH_LOAN";
82
+ ComposerCommands[ComposerCommands["ERC4646"] = 224] = "ERC4646";
83
+ ComposerCommands[ComposerCommands["GEN_2025_SINGELTONS"] = 225] = "GEN_2025_SINGELTONS";
84
+ })(ComposerCommands || (ComposerCommands = {}));
85
+ export var ForwarderCommands;
86
+ (function (ForwarderCommands) {
87
+ ForwarderCommands[ForwarderCommands["EXT_CALL"] = 64] = "EXT_CALL";
88
+ ForwarderCommands[ForwarderCommands["ASSET_HANDLING"] = 128] = "ASSET_HANDLING";
89
+ })(ForwarderCommands || (ForwarderCommands = {}));
90
+ export var DexTypeMappings;
91
+ (function (DexTypeMappings) {
92
+ DexTypeMappings[DexTypeMappings["UNISWAP_V3_ID"] = 0] = "UNISWAP_V3_ID";
93
+ DexTypeMappings[DexTypeMappings["IZI_ID"] = 1] = "IZI_ID";
94
+ DexTypeMappings[DexTypeMappings["UNISWAP_V4_ID"] = 2] = "UNISWAP_V4_ID";
95
+ DexTypeMappings[DexTypeMappings["BALANCER_V3_ID"] = 4] = "BALANCER_V3_ID";
96
+ DexTypeMappings[DexTypeMappings["BALANCER_V2_ID"] = 3] = "BALANCER_V2_ID";
97
+ DexTypeMappings[DexTypeMappings["UNISWAP_V2_ID"] = 6] = "UNISWAP_V2_ID";
98
+ DexTypeMappings[DexTypeMappings["UNISWAP_V2_FOT_ID"] = 7] = "UNISWAP_V2_FOT_ID";
99
+ DexTypeMappings[DexTypeMappings["CURVE_V1_STANDARD_ID"] = 60] = "CURVE_V1_STANDARD_ID";
100
+ DexTypeMappings[DexTypeMappings["CURVE_FORK_ID"] = 61] = "CURVE_FORK_ID";
101
+ DexTypeMappings[DexTypeMappings["UNISWAP_V2_MAX_ID"] = 150] = "UNISWAP_V2_MAX_ID";
102
+ DexTypeMappings[DexTypeMappings["CURVE_RECEIVED_ID"] = 150] = "CURVE_RECEIVED_ID";
103
+ DexTypeMappings[DexTypeMappings["WOO_FI_ID"] = 155] = "WOO_FI_ID";
104
+ DexTypeMappings[DexTypeMappings["LB_ID"] = 160] = "LB_ID";
105
+ DexTypeMappings[DexTypeMappings["GMX_ID"] = 170] = "GMX_ID";
106
+ DexTypeMappings[DexTypeMappings["KTX_ID"] = 171] = "KTX_ID";
107
+ DexTypeMappings[DexTypeMappings["MAX_GMX_ID"] = 173] = "MAX_GMX_ID";
108
+ DexTypeMappings[DexTypeMappings["DODO_ID"] = 180] = "DODO_ID";
109
+ DexTypeMappings[DexTypeMappings["SYNC_SWAP_ID"] = 190] = "SYNC_SWAP_ID";
110
+ DexTypeMappings[DexTypeMappings["NATIVE_WRAP_ID"] = 254] = "NATIVE_WRAP_ID";
111
+ })(DexTypeMappings || (DexTypeMappings = {}));
112
+ export var DexForkMappings;
113
+ (function (DexForkMappings) {
114
+ DexForkMappings[DexForkMappings["UNISWAP_V3"] = 0] = "UNISWAP_V3";
115
+ DexForkMappings[DexForkMappings["IZI"] = 0] = "IZI";
116
+ DexForkMappings[DexForkMappings["ANY_V3"] = 255] = "ANY_V3";
117
+ DexForkMappings[DexForkMappings["ANY_IZI"] = 255] = "ANY_IZI";
118
+ DexForkMappings[DexForkMappings["UNISWAP_V4"] = 0] = "UNISWAP_V4";
119
+ DexForkMappings[DexForkMappings["BALANCER_V3"] = 0] = "BALANCER_V3";
120
+ DexForkMappings[DexForkMappings["UNISWAP_V2"] = 0] = "UNISWAP_V2";
121
+ })(DexForkMappings || (DexForkMappings = {}));
122
+ export function encodePermit2TransferFrom(token, receiver, amount) {
123
+ return encodePacked(["uint8", "uint8", "address", "address", "uint128"], [uint8(ComposerCommands.TRANSFERS), uint8(TransferIds.PERMIT2_TRANSFER_FROM), token, receiver, uint128(amount)]);
124
+ }
125
+ export function encodeNextGenDexUnlock(singleton, id, d) {
126
+ return encodePacked(["uint8", "uint8", "address", "uint16", "uint8", "bytes"], [
127
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
128
+ uint8(Gen2025ActionIds.UNLOCK),
129
+ singleton,
130
+ uint16(d.length / 2 - 1 + 1),
131
+ uint8(id),
132
+ d,
133
+ ]);
134
+ }
135
+ export function encodeBalancerV3FlashLoan(singleton, poolId, asset, receiver, amount, flashData) {
136
+ const take = encodeBalancerV3Take(singleton, asset, receiver, amount);
137
+ const settle = encodeNextGenDexSettleBalancer(singleton, asset, amount);
138
+ return encodeNextGenDexUnlock(singleton, poolId, encodeBalancerV3FlashLoanData(take, flashData, settle));
139
+ }
140
+ export function encodeBalancerV3FlashLoanData(take, flashData, settle) {
141
+ return encodePacked(["bytes", "bytes", "bytes"], [take, flashData, settle]);
142
+ }
143
+ export function encodeUniswapV4FlashLoan(singleton, poolId, asset, receiver, amount, flashData) {
144
+ const take = encodeUniswapV4Take(singleton, asset, receiver, amount);
145
+ const settle = encodeNextGenDexSettle(singleton, asset === zeroAddress ? amount : 0);
146
+ const sync = encodeUniswapV4Sync(singleton, asset);
147
+ return encodeNextGenDexUnlock(singleton, poolId, encodeUniswapV4FlashLoanData(take, sync, flashData, settle));
148
+ }
149
+ export function encodeUniswapV4FlashLoanData(take, sync, flashData, settle) {
150
+ return encodePacked(["bytes", "bytes", "bytes", "bytes"], [take, sync, flashData, settle]);
151
+ }
152
+ export function encodeBalancerV3Take(singleton, asset, receiver, amount) {
153
+ return encodePacked(["uint8", "uint8", "address", "address", "address", "uint128"], [
154
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
155
+ uint8(Gen2025ActionIds.BAL_V3_TAKE),
156
+ singleton,
157
+ asset,
158
+ receiver,
159
+ uint128(amount),
160
+ ]);
161
+ }
162
+ export function encodeUniswapV4Sync(singleton, asset) {
163
+ if (asset === zeroAddress)
164
+ return `0x0`;
165
+ return encodePacked(["uint8", "uint8", "address", "address"], [uint8(ComposerCommands.GEN_2025_SINGELTONS), uint8(Gen2025ActionIds.UNI_V4_SYNC), singleton, asset]);
166
+ }
167
+ export function encodeUniswapV4Take(singleton, asset, receiver, amount) {
168
+ return encodePacked(["uint8", "uint8", "address", "address", "address", "uint128"], [
169
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
170
+ uint8(Gen2025ActionIds.UNI_V4_TAKE),
171
+ singleton,
172
+ asset,
173
+ receiver,
174
+ uint128(amount),
175
+ ]);
176
+ }
177
+ export function swapHead(amount, amountOutMin, assetIn) {
178
+ return encodePacked(["uint8", "uint128", "uint128", "address"], [
179
+ uint8(ComposerCommands.SWAPS),
180
+ generateAmountBitmap(uint128(amount), false, false),
181
+ uint128(amountOutMin),
182
+ assetIn,
183
+ ]);
184
+ }
185
+ export function attachBranch(data, hops, splits, splitsData) {
186
+ if (hops !== 0n && splits !== 0n)
187
+ throw new Error("Invalidbranching");
188
+ if (splitsData.length / 2 - 1 > 0 && splits === 0n)
189
+ throw new Error("Nosplitsbutsplitdataprovided");
190
+ return encodePacked(["bytes", "uint8", "uint8", "bytes"], [data, uint8(hops), uint8(splits), splitsData]);
191
+ }
192
+ export function uniswapV2StyleSwap(tokenOut, receiver, forkId, pool, feeDenom, cfg, flashCalldata) {
193
+ if (uint256(cfg) < 2 && flashCalldata.length / 2 - 1 > 2)
194
+ throw new Error("Invalidconfigforv2swap");
195
+ return encodePacked(["address", "address", "uint8", "address", "uint16", "uint8", "uint16", "bytes"], [
196
+ tokenOut,
197
+ receiver,
198
+ uint8(DexTypeMappings.UNISWAP_V2_ID),
199
+ pool,
200
+ uint16(feeDenom),
201
+ uint8(forkId),
202
+ uint16(flashCalldata.length / 2 - 1),
203
+ bytes(cfg === DexPayConfig.FLASH ? flashCalldata : newbytes(0)),
204
+ ]);
205
+ }
206
+ export function uniswapV4StyleSwap(currentData, tokenOut, receiver, manager, fee, tickSpacing, hooks, hookData, cfg) {
207
+ if (cfg === DexPayConfig.FLASH)
208
+ throw new Error("Invalidconfigforv2swap");
209
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "address", "uint24", "uint24", "uint8", "uint16", "bytes"], [
210
+ currentData,
211
+ tokenOut,
212
+ receiver,
213
+ uint8(DexTypeMappings.UNISWAP_V4_ID),
214
+ hooks,
215
+ manager,
216
+ fee,
217
+ tickSpacing,
218
+ uint8(uint256(cfg)),
219
+ uint16(hookData.length / 2 - 1),
220
+ hookData,
221
+ ]);
222
+ }
223
+ export function balancerV2StyleSwap(currentData, tokenOut, receiver, poolId, balancerVault, cfg) {
224
+ if (cfg === DexPayConfig.FLASH)
225
+ throw new Error("Invalidconfigforv2swap");
226
+ return encodePacked(["bytes", "address", "address", "uint8", "bytes32", "address", "uint16"], [
227
+ currentData,
228
+ tokenOut,
229
+ receiver,
230
+ uint8(DexTypeMappings.BALANCER_V2_ID),
231
+ poolId,
232
+ balancerVault,
233
+ uint16(uint256(cfg)),
234
+ ]);
235
+ }
236
+ export function lbStyleSwap(currentData, tokenOut, receiver, pool, swapForY, cfg) {
237
+ if (cfg === DexPayConfig.FLASH)
238
+ throw new Error("Invalidconfigforv2swap");
239
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8", "uint16"], [
240
+ currentData,
241
+ tokenOut,
242
+ receiver,
243
+ uint8(DexTypeMappings.LB_ID),
244
+ pool,
245
+ uint8(swapForY ? 1 : 0),
246
+ uint16(uint256(cfg)),
247
+ ]);
248
+ }
249
+ export function syncSwapStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
250
+ if (cfg === DexPayConfig.FLASH)
251
+ throw new Error("Invalidconfigforv2swap");
252
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint16"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.SYNC_SWAP_ID), pool, uint16(uint256(cfg))]);
253
+ }
254
+ export function uniswapV3StyleSwap(currentData, tokenOut, receiver, forkId, pool, feeTier, cfg, flashCalldata) {
255
+ if (uint256(cfg) < 2 && flashCalldata.length / 2 - 1 > 2)
256
+ throw new Error("Invalidconfigforv2swap");
257
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8", "uint16", "uint16", "bytes"], [
258
+ currentData,
259
+ tokenOut,
260
+ receiver,
261
+ uint8(DexTypeMappings.UNISWAP_V3_ID),
262
+ pool,
263
+ uint8(forkId),
264
+ uint16(feeTier),
265
+ uint16(cfg === DexPayConfig.FLASH ? flashCalldata.length / 2 - 1 : uint256(cfg)),
266
+ bytes(cfg === DexPayConfig.FLASH ? flashCalldata : newbytes(0)),
267
+ ]);
268
+ }
269
+ export function izumiV3StyleSwap(currentData, tokenOut, receiver, forkId, pool, feeTier, cfg, flashCalldata) {
270
+ if (uint256(cfg) < 2 && flashCalldata.length / 2 - 1 > 2)
271
+ throw new Error("Invalidconfigforv2swap");
272
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8", "uint16", "uint16", "bytes"], [
273
+ currentData,
274
+ tokenOut,
275
+ receiver,
276
+ uint8(DexTypeMappings.IZI_ID),
277
+ pool,
278
+ uint8(forkId),
279
+ uint16(feeTier),
280
+ uint16(cfg === DexPayConfig.FLASH ? flashCalldata.length / 2 - 1 : uint256(cfg)),
281
+ bytes(cfg === DexPayConfig.FLASH ? flashCalldata : newbytes(0)),
282
+ ]);
283
+ }
284
+ export function balancerV3StyleSwap(currentData, tokenOut, receiver, balancerV3Vault, pool, cfg, poolUserData) {
285
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "address", "uint8", "uint16", "bytes"], [
286
+ currentData,
287
+ tokenOut,
288
+ receiver,
289
+ uint8(DexTypeMappings.BALANCER_V3_ID),
290
+ pool,
291
+ balancerV3Vault,
292
+ uint8(cfg),
293
+ uint16(poolUserData.length / 2 - 1),
294
+ poolUserData,
295
+ ]);
296
+ }
297
+ export function encodeIzumiStyleSwap(tokenOut, receiver, forkId, pool, feeTier, cfg, flashCalldata) {
298
+ if (uint256(cfg) < 2 && flashCalldata.length / 2 - 1 > 2)
299
+ throw new Error("Invalidconfigforv2swap");
300
+ return encodePacked(["address", "address", "uint8", "address", "uint8", "uint16", "uint16", "bytes"], [
301
+ tokenOut,
302
+ receiver,
303
+ uint8(DexTypeMappings.IZI_ID),
304
+ pool,
305
+ uint8(forkId),
306
+ uint16(feeTier),
307
+ uint16(cfg === DexPayConfig.FLASH ? flashCalldata.length / 2 - 1 : uint256(cfg)),
308
+ bytes(cfg === DexPayConfig.FLASH ? flashCalldata : newbytes(0)),
309
+ ]);
310
+ }
311
+ export function encodeDodoStyleSwap(currentData, tokenOut, receiver, pool, selector, poolId, cfg, flashCalldata) {
312
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint8", "uint16", "uint16", "bytes"], [
313
+ currentData,
314
+ tokenOut,
315
+ receiver,
316
+ uint8(DexTypeMappings.DODO_ID),
317
+ pool,
318
+ uint8(selector),
319
+ uint16(poolId),
320
+ uint16(cfg === DexPayConfig.FLASH ? flashCalldata.length / 2 - 1 : uint256(cfg)),
321
+ bytes(cfg === DexPayConfig.FLASH ? flashCalldata : newbytes(0)),
322
+ ]);
323
+ }
324
+ export function encodeWooStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
325
+ if (cfg === DexPayConfig.FLASH)
326
+ throw new Error("NoflashforWoo");
327
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint16"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.WOO_FI_ID), pool, uint16(uint256(cfg))]);
328
+ }
329
+ export function encodeGmxStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
330
+ if (cfg === DexPayConfig.FLASH)
331
+ throw new Error("NoflashforWoo");
332
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint16"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.GMX_ID), pool, uint16(uint256(cfg))]);
333
+ }
334
+ export function encodeKtxStyleSwap(currentData, tokenOut, receiver, pool, cfg) {
335
+ if (cfg === DexPayConfig.FLASH)
336
+ throw new Error("NoflashforWoo");
337
+ return encodePacked(["bytes", "address", "address", "uint8", "address", "uint16"], [currentData, tokenOut, receiver, uint8(DexTypeMappings.KTX_ID), pool, uint16(uint256(cfg))]);
338
+ }
339
+ export function encodeCurveStyleSwap(tokenOut, receiver, pool, indexIn, indexOut, selectorId, cfg) {
340
+ if (cfg === DexPayConfig.FLASH)
341
+ throw new Error("FlashnotyetsupportedforCurve");
342
+ return encodePacked(["address", "address", "uint8", "address", "uint8", "uint8", "uint8", "uint16"], [
343
+ tokenOut,
344
+ receiver,
345
+ uint8(DexTypeMappings.CURVE_V1_STANDARD_ID),
346
+ pool,
347
+ uint8(indexIn),
348
+ uint8(indexOut),
349
+ uint8(selectorId),
350
+ uint16(uint256(cfg)),
351
+ ]);
352
+ }
353
+ export function encodeCurveNGStyleSwap(tokenOut, receiver, pool, indexIn, indexOut, selectorId, cfg) {
354
+ if (cfg === DexPayConfig.FLASH)
355
+ throw new Error("FlashnotyetsupportedforCurve");
356
+ return encodePacked(["address", "address", "uint8", "address", "uint8", "uint8", "uint8", "uint16"], [
357
+ tokenOut,
358
+ receiver,
359
+ uint8(DexTypeMappings.CURVE_RECEIVED_ID),
360
+ pool,
361
+ uint8(indexIn),
362
+ uint8(indexOut),
363
+ uint8(selectorId),
364
+ uint16(uint256(cfg)),
365
+ ]);
366
+ }
367
+ export function encodeNextGenDexSettle(singleton, nativeAmount) {
368
+ return encodePacked(["uint8", "uint8", "address", "uint128"], [
369
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
370
+ uint8(Gen2025ActionIds.UNI_V4_SETTLE),
371
+ singleton,
372
+ uint128(nativeAmount),
373
+ ]);
374
+ }
375
+ export function encodeNextGenDexSettleBalancer(singleton, asset, amountHint) {
376
+ return encodePacked(["uint8", "uint8", "address", "address", "uint128"], [
377
+ uint8(ComposerCommands.GEN_2025_SINGELTONS),
378
+ uint8(Gen2025ActionIds.BAL_V3_SETTLE),
379
+ singleton,
380
+ asset,
381
+ uint128(amountHint >= 0xffffffffffffffffffffffffffffffn ? 0xffffffffffffffffffffffffffffffn : amountHint),
382
+ ]);
383
+ }
384
+ export function encodeTransferIn(asset, receiver, amount) {
385
+ return encodePacked(["uint8", "uint8", "address", "address", "uint128"], [uint8(ComposerCommands.TRANSFERS), uint8(TransferIds.TRANSFER_FROM), asset, receiver, uint128(amount)]);
386
+ }
387
+ export function encodeSweep(asset, receiver, amount, sweepType) {
388
+ return encodePacked(["uint8", "uint8", "address", "address", "uint8", "uint128"], [uint8(ComposerCommands.TRANSFERS), uint8(TransferIds.SWEEP), asset, receiver, sweepType, uint128(amount)]);
389
+ }
390
+ export function encodeWrap(amount, wrapTarget) {
391
+ return encodePacked(["uint8", "uint8", "address", "address", "uint8", "uint128"], [
392
+ uint8(ComposerCommands.TRANSFERS),
393
+ uint8(TransferIds.SWEEP),
394
+ zeroAddress,
395
+ wrapTarget,
396
+ uint8(SweepType.AMOUNT),
397
+ uint128(amount),
398
+ ]);
399
+ }
400
+ export function encodeApprove(asset, target) {
401
+ return encodePacked(["uint8", "uint8", "address", "address"], [uint8(ComposerCommands.TRANSFERS), uint8(TransferIds.APPROVE), asset, target]);
402
+ }
403
+ export function encodeUnwrap(target, receiver, amount, sweepType) {
404
+ return encodePacked(["uint8", "uint8", "address", "address", "uint8", "uint128"], [
405
+ uint8(ComposerCommands.TRANSFERS),
406
+ uint8(TransferIds.UNWRAP_WNATIVE),
407
+ target,
408
+ receiver,
409
+ sweepType,
410
+ uint128(amount),
411
+ ]);
412
+ }
413
+ export function encodeBalancerV2FlashLoan(asset, amount, poolId, data) {
414
+ return encodePacked(["uint8", "uint8", "address", "uint128", "uint16", "bytes"], [
415
+ uint8(ComposerCommands.FLASH_LOAN),
416
+ uint8(FlashLoanIds.BALANCER_V2),
417
+ asset,
418
+ uint128(amount),
419
+ uint16(data.length / 2 - 1 + 1),
420
+ encodeUint8AndBytes(poolId, data),
421
+ ]);
422
+ }
423
+ export function encodeFlashLoan(asset, amount, pool, poolType, poolId, data) {
424
+ return encodePacked(["bytes", "uint8", "uint8", "address", "address", "uint128", "uint16", "bytes"], [
425
+ encodeApprove(asset, pool),
426
+ uint8(ComposerCommands.FLASH_LOAN),
427
+ poolType,
428
+ asset,
429
+ pool,
430
+ uint128(amount),
431
+ uint16(data.length / 2 - 1 + 1),
432
+ encodeUint8AndBytes(poolId, data),
433
+ ]);
434
+ }
435
+ export function encodeUint8AndBytes(poolId, data) {
436
+ return encodePacked(["uint8", "bytes"], [uint8(poolId), data]);
437
+ }
438
+ export function encodeMorphoMarket(loanToken, collateralToken, oracle, irm, lltv) {
439
+ return encodePacked(["address", "address", "address", "address", "uint128"], [loanToken, collateralToken, oracle, irm, uint128(lltv)]);
440
+ }
441
+ export function encodeMorphoDepositCollateral(market, assets, receiver, data, morphoB, pId) {
442
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "bytes", "uint128", "address", "address", "uint16", "bytes"], [
443
+ encodeApprove(getMorphoCollateral(market), morphoB),
444
+ uint8(ComposerCommands.LENDING),
445
+ uint8(LenderOps.DEPOSIT),
446
+ uint16(LenderIds.UP_TO_MORPHO),
447
+ market,
448
+ uint128(assets),
449
+ receiver,
450
+ morphoB,
451
+ uint16(data.length / 2 - 1 > 0 ? data.length / 2 - 1 + 1 : 0),
452
+ data.length / 2 - 1 === 0 ? newbytes(0) : encodeUint8AndBytes(uint8(pId), data),
453
+ ]);
454
+ }
455
+ export function encodeMorphoDeposit(market, isShares, assets, receiver, data, morphoB, pId) {
456
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "bytes", "uint128", "address", "address", "uint16", "bytes"], [
457
+ encodeApprove(getMorphoLoanAsset(market), morphoB),
458
+ uint8(ComposerCommands.LENDING),
459
+ uint8(LenderOps.DEPOSIT_LENDING_TOKEN),
460
+ uint16(LenderIds.UP_TO_MORPHO),
461
+ market,
462
+ generateAmountBitmap(uint128(assets), isShares, false),
463
+ receiver,
464
+ morphoB,
465
+ uint16(data.length / 2 - 1 > 0 ? data.length / 2 - 1 + 1 : 0),
466
+ data.length / 2 - 1 === 0 ? newbytes(0) : encodeUint8AndBytes(uint8(pId), data),
467
+ ]);
468
+ }
469
+ export function encodeErc4646Deposit(asset, vault, isShares, assets, receiver) {
470
+ return encodePacked(["bytes", "uint8", "uint8", "address", "address", "uint128", "address"], [
471
+ encodeApprove(asset, vault),
472
+ uint8(ComposerCommands.ERC4646),
473
+ uint8(0),
474
+ asset,
475
+ vault,
476
+ generateAmountBitmap(uint128(assets), isShares, false),
477
+ receiver,
478
+ ]);
479
+ }
480
+ export function encodeErc4646Withdraw(vault, isShares, assets, receiver) {
481
+ return encodePacked(["uint8", "uint8", "address", "uint128", "address"], [
482
+ uint8(ComposerCommands.ERC4646),
483
+ uint8(1),
484
+ vault,
485
+ generateAmountBitmap(uint128(assets), isShares, false),
486
+ receiver,
487
+ ]);
488
+ }
489
+ export function encodeMorphoWithdraw(market, isShares, assets, receiver, morphoB) {
490
+ return encodePacked(["uint8", "uint8", "uint16", "bytes", "uint128", "address", "address"], [
491
+ uint8(ComposerCommands.LENDING),
492
+ uint8(LenderOps.WITHDRAW_LENDING_TOKEN),
493
+ uint16(LenderIds.UP_TO_MORPHO),
494
+ market,
495
+ generateAmountBitmap(uint128(assets), isShares, false),
496
+ receiver,
497
+ morphoB,
498
+ ]);
499
+ }
500
+ export function encodeMorphoWithdrawCollateral(market, assets, receiver, morphoB) {
501
+ return encodePacked(["uint8", "uint8", "uint16", "bytes", "uint128", "address", "address"], [
502
+ uint8(ComposerCommands.LENDING),
503
+ uint8(LenderOps.WITHDRAW),
504
+ uint16(LenderIds.UP_TO_MORPHO),
505
+ market,
506
+ uint128(assets),
507
+ receiver,
508
+ morphoB,
509
+ ]);
510
+ }
511
+ export function encodeMorphoBorrow(market, isShares, assets, receiver, morphoB) {
512
+ return encodePacked(["uint8", "uint8", "uint16", "bytes", "uint128", "address", "address"], [
513
+ uint8(ComposerCommands.LENDING),
514
+ uint8(LenderOps.BORROW),
515
+ uint16(LenderIds.UP_TO_MORPHO),
516
+ market,
517
+ generateAmountBitmap(uint128(assets), isShares, false),
518
+ receiver,
519
+ morphoB,
520
+ ]);
521
+ }
522
+ export function encodeMorphoRepay(market, isShares, unsafe, assets, receiver, data, morphoB, pId) {
523
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "bytes", "uint128", "address", "address", "uint16", "bytes"], [
524
+ encodeApprove(getMorphoLoanAsset(market), morphoB),
525
+ uint8(ComposerCommands.LENDING),
526
+ uint8(LenderOps.REPAY),
527
+ uint16(LenderIds.UP_TO_MORPHO),
528
+ market,
529
+ generateAmountBitmap(uint128(assets), isShares, unsafe),
530
+ receiver,
531
+ morphoB,
532
+ uint16(data.length / 2 - 1 > 0 ? data.length / 2 - 1 + 1 : 0),
533
+ data.length / 2 - 1 === 0 ? newbytes(0) : encodeUint8AndBytes(uint8(pId), data),
534
+ ]);
535
+ }
536
+ export function encodeAaveDeposit(token, amount, receiver, pool) {
537
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
538
+ encodeApprove(token, pool),
539
+ uint8(ComposerCommands.LENDING),
540
+ uint8(LenderOps.DEPOSIT),
541
+ uint16(LenderIds.UP_TO_AAVE_V3 - 1),
542
+ token,
543
+ uint128(amount),
544
+ receiver,
545
+ pool,
546
+ ]);
547
+ }
548
+ export function encodeAaveBorrow(token, amount, receiver, mode, pool) {
549
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address"], [
550
+ uint8(ComposerCommands.LENDING),
551
+ uint8(LenderOps.BORROW),
552
+ uint16(LenderIds.UP_TO_AAVE_V3 - 1),
553
+ token,
554
+ uint128(amount),
555
+ receiver,
556
+ uint8(mode),
557
+ pool,
558
+ ]);
559
+ }
560
+ export function encodeAaveRepay(token, amount, receiver, mode, dToken, pool) {
561
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address", "address"], [
562
+ encodeApprove(token, pool),
563
+ uint8(ComposerCommands.LENDING),
564
+ uint8(LenderOps.REPAY),
565
+ uint16(LenderIds.UP_TO_AAVE_V3 - 1),
566
+ token,
567
+ uint128(amount),
568
+ receiver,
569
+ uint8(mode),
570
+ dToken,
571
+ pool,
572
+ ]);
573
+ }
574
+ export function encodeAaveWithdraw(token, amount, receiver, aToken, pool) {
575
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address", "address"], [
576
+ uint8(ComposerCommands.LENDING),
577
+ uint8(LenderOps.WITHDRAW),
578
+ uint16(LenderIds.UP_TO_AAVE_V3 - 1),
579
+ token,
580
+ uint128(amount),
581
+ receiver,
582
+ aToken,
583
+ pool,
584
+ ]);
585
+ }
586
+ export function encodeAaveV2Deposit(token, amount, receiver, pool) {
587
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
588
+ encodeApprove(token, pool),
589
+ uint8(ComposerCommands.LENDING),
590
+ uint8(LenderOps.DEPOSIT),
591
+ uint16(LenderIds.UP_TO_AAVE_V2 - 1),
592
+ token,
593
+ uint128(amount),
594
+ receiver,
595
+ pool,
596
+ ]);
597
+ }
598
+ export function encodeAaveV2Borrow(token, amount, receiver, mode, pool) {
599
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address"], [
600
+ uint8(ComposerCommands.LENDING),
601
+ uint8(LenderOps.BORROW),
602
+ uint16(LenderIds.UP_TO_AAVE_V2 - 1),
603
+ token,
604
+ uint128(amount),
605
+ receiver,
606
+ uint8(mode),
607
+ pool,
608
+ ]);
609
+ }
610
+ export function encodeAaveV2Repay(token, amount, receiver, mode, dToken, pool) {
611
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address", "address"], [
612
+ encodeApprove(token, pool),
613
+ uint8(ComposerCommands.LENDING),
614
+ uint8(LenderOps.REPAY),
615
+ uint16(LenderIds.UP_TO_AAVE_V2 - 1),
616
+ token,
617
+ uint128(amount),
618
+ receiver,
619
+ uint8(mode),
620
+ dToken,
621
+ pool,
622
+ ]);
623
+ }
624
+ export function encodeAaveV2Withdraw(token, amount, receiver, aToken, pool) {
625
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address", "address"], [
626
+ uint8(ComposerCommands.LENDING),
627
+ uint8(LenderOps.WITHDRAW),
628
+ uint16(LenderIds.UP_TO_AAVE_V2 - 1),
629
+ token,
630
+ uint128(amount),
631
+ receiver,
632
+ aToken,
633
+ pool,
634
+ ]);
635
+ }
636
+ export function encodeCompoundV3Deposit(token, amount, receiver, comet) {
637
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
638
+ encodeApprove(token, comet),
639
+ uint8(ComposerCommands.LENDING),
640
+ uint8(LenderOps.DEPOSIT),
641
+ uint16(LenderIds.UP_TO_COMPOUND_V3 - 1),
642
+ token,
643
+ uint128(amount),
644
+ receiver,
645
+ comet,
646
+ ]);
647
+ }
648
+ export function encodeCompoundV3Borrow(token, amount, receiver, comet) {
649
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
650
+ uint8(ComposerCommands.LENDING),
651
+ uint8(LenderOps.BORROW),
652
+ uint16(LenderIds.UP_TO_COMPOUND_V3 - 1),
653
+ token,
654
+ uint128(amount),
655
+ receiver,
656
+ comet,
657
+ ]);
658
+ }
659
+ export function encodeCompoundV3Repay(token, amount, receiver, comet) {
660
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
661
+ encodeApprove(token, comet),
662
+ uint8(ComposerCommands.LENDING),
663
+ uint8(LenderOps.REPAY),
664
+ uint16(LenderIds.UP_TO_COMPOUND_V3 - 1),
665
+ token,
666
+ uint128(amount),
667
+ receiver,
668
+ comet,
669
+ ]);
670
+ }
671
+ export function encodeCompoundV3Withdraw(token, amount, receiver, comet, isBase) {
672
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "uint8", "address"], [
673
+ uint8(ComposerCommands.LENDING),
674
+ uint8(LenderOps.WITHDRAW),
675
+ uint16(LenderIds.UP_TO_COMPOUND_V3 - 1),
676
+ token,
677
+ uint128(amount),
678
+ receiver,
679
+ isBase ? uint8(1) : uint8(0),
680
+ comet,
681
+ ]);
682
+ }
683
+ export function encodeCompoundV2Deposit(token, amount, receiver, cToken) {
684
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
685
+ token === zeroAddress ? newbytes(0) : encodeApprove(token, cToken),
686
+ uint8(ComposerCommands.LENDING),
687
+ uint8(LenderOps.DEPOSIT),
688
+ uint16(LenderIds.UP_TO_COMPOUND_V2 - 1),
689
+ token,
690
+ uint128(amount),
691
+ receiver,
692
+ cToken,
693
+ ]);
694
+ }
695
+ export function encodeCompoundV2Borrow(token, amount, receiver, cToken) {
696
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
697
+ uint8(ComposerCommands.LENDING),
698
+ uint8(LenderOps.BORROW),
699
+ uint16(LenderIds.UP_TO_COMPOUND_V2 - 1),
700
+ token,
701
+ uint128(amount),
702
+ receiver,
703
+ cToken,
704
+ ]);
705
+ }
706
+ export function encodeCompoundV2Repay(token, amount, receiver, cToken) {
707
+ return encodePacked(["bytes", "uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
708
+ token === zeroAddress ? newbytes(0) : encodeApprove(token, cToken),
709
+ uint8(ComposerCommands.LENDING),
710
+ uint8(LenderOps.REPAY),
711
+ uint16(LenderIds.UP_TO_COMPOUND_V2 - 1),
712
+ token,
713
+ uint128(amount),
714
+ receiver,
715
+ cToken,
716
+ ]);
717
+ }
718
+ export function encodeCompoundV2Withdraw(token, amount, receiver, cToken) {
719
+ return encodePacked(["uint8", "uint8", "uint16", "address", "uint128", "address", "address"], [
720
+ uint8(ComposerCommands.LENDING),
721
+ uint8(LenderOps.WITHDRAW),
722
+ uint16(LenderIds.UP_TO_COMPOUND_V2 - 1),
723
+ token,
724
+ uint128(amount),
725
+ receiver,
726
+ cToken,
727
+ ]);
728
+ }
@@ -0,0 +1,2 @@
1
+ export * from './CalldataLib';
2
+ export * from './utils';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './CalldataLib';
2
+ export * from './utils';
@@ -0,0 +1,19 @@
1
+ import { type Hex, type Address } from "viem";
2
+ export declare const _PRE_PARAM: 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): 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/dist/utils.js ADDED
@@ -0,0 +1,59 @@
1
+ import { encodePacked as abiEncodePacked } from "viem";
2
+ export const _PRE_PARAM = 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) {
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
+ return am;
45
+ }
46
+ export function getMorphoCollateral(market) {
47
+ const slice = market.slice(42, 82);
48
+ return `0x${slice}`;
49
+ }
50
+ export function getMorphoLoanAsset(market) {
51
+ const slice = market.slice(2, 42);
52
+ return `0x${slice}`;
53
+ }
54
+ export function newbytes(length) {
55
+ return ("0x" + "0".repeat(length * 2));
56
+ }
57
+ export function bytes(value) {
58
+ return value;
59
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@1delta/calldatalib",
3
+ "version": "0.0.2",
4
+ "description": "Generated CalldataLib TypeScript functions for 1delta smart contracts",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "keywords": [
12
+ "ethereum",
13
+ "1delta"
14
+ ],
15
+ "license": "MIT",
16
+ "devDependencies": {
17
+ "typescript": "^5.0.0",
18
+ "@types/node": "^18.0.0"
19
+ },
20
+ "dependencies": {
21
+ "viem": "^2.24.1"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc"
25
+ }
26
+ }