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