@1delta/calldatalib 0.0.39 → 0.0.42

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.
@@ -10,8 +10,12 @@ exports.encodeStargateV2BridgeSimpleTaxi = encodeStargateV2BridgeSimpleTaxi;
10
10
  exports.encodeStargateV2BridgeSimpleBus = encodeStargateV2BridgeSimpleBus;
11
11
  exports.encodeAcrossBridgeToken = encodeAcrossBridgeToken;
12
12
  exports.encodeAcrossBridgeNative = encodeAcrossBridgeNative;
13
+ exports.encodeAcrossHeader = encodeAcrossHeader;
14
+ exports.encodeAcrossParams = encodeAcrossParams;
13
15
  exports.encodeSquidRouterCall = encodeSquidRouterCall;
14
16
  exports.encodeSquidRouterCallPartial = encodeSquidRouterCallPartial;
17
+ exports.encodeGasZipBridge = encodeGasZipBridge;
18
+ exports.encodeGasZipEvmBridge = encodeGasZipEvmBridge;
15
19
  exports.encodePermit2TransferFrom = encodePermit2TransferFrom;
16
20
  exports.encodeNextGenDexUnlock = encodeNextGenDexUnlock;
17
21
  exports.encodeBalancerV3FlashLoan = encodeBalancerV3FlashLoan;
@@ -170,6 +174,7 @@ var BridgeIds;
170
174
  BridgeIds[BridgeIds["STARGATE_V2"] = 0] = "STARGATE_V2";
171
175
  BridgeIds[BridgeIds["ACROSS"] = 10] = "ACROSS";
172
176
  BridgeIds[BridgeIds["SQUID_ROUTER"] = 20] = "SQUID_ROUTER";
177
+ BridgeIds[BridgeIds["GASZIP"] = 30] = "GASZIP";
173
178
  })(BridgeIds || (exports.BridgeIds = BridgeIds = {}));
174
179
  var DexTypeMappings;
175
180
  (function (DexTypeMappings) {
@@ -257,69 +262,41 @@ function encodeStargateV2BridgeSimpleTaxi(asset, stargatePool, dstEid, receiver,
257
262
  function encodeStargateV2BridgeSimpleBus(asset, stargatePool, dstEid, receiver, refundReceiver, amount, isNative, slippage, fee) {
258
263
  return encodeStargateV2Bridge(asset, stargatePool, dstEid, receiver, refundReceiver, amount, slippage, fee, true, isNative, (0, utils_js_1.newbytes)(0), (0, utils_js_1.newbytes)(0));
259
264
  }
260
- function encodeAcrossBridgeToken(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, receiver, message) {
261
- const bridgeData = (0, utils_js_1.encodePacked)([
262
- "uint8",
263
- "uint8",
264
- "address",
265
- "address",
266
- "address",
267
- "bytes32",
268
- "uint128",
269
- "uint128",
270
- "uint32",
271
- "uint32",
272
- "bytes32",
273
- "uint16",
274
- "bytes",
275
- ], [
276
- (0, utils_js_1.uint8)(ComposerCommands.BRIDGING),
277
- (0, utils_js_1.uint8)(BridgeIds.ACROSS),
278
- spokePool,
279
- depositor,
280
- sendingAssetId,
281
- receivingAssetId,
282
- (0, utils_js_1.generateAmountBitmap)((0, utils_js_1.uint128)(amount), false, false),
283
- fixedFee,
284
- feePercentage,
285
- destinationChainId,
286
- receiver,
287
- (0, utils_js_1.uint16)(message.length / 2 - 1),
288
- message,
265
+ function encodeAcrossBridgeToken(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message) {
266
+ return (0, utils_js_1.encodePacked)(["bytes", "bytes"], [
267
+ encodeAcrossHeader(spokePool, depositor, sendingAssetId, receivingAssetId, amount, false),
268
+ encodeAcrossParams(fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message),
269
+ ]);
270
+ }
271
+ function encodeAcrossBridgeNative(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message) {
272
+ return (0, utils_js_1.encodePacked)(["bytes", "bytes"], [
273
+ encodeAcrossHeader(spokePool, depositor, sendingAssetId, receivingAssetId, amount, true),
274
+ encodeAcrossParams(fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message),
289
275
  ]);
290
- return bridgeData;
291
- }
292
- function encodeAcrossBridgeNative(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, receiver, message) {
293
- const bridgeData = (0, utils_js_1.encodePacked)([
294
- "uint8",
295
- "uint8",
296
- "address",
297
- "address",
298
- "address",
299
- "bytes32",
300
- "uint128",
301
- "uint128",
302
- "uint32",
303
- "uint32",
304
- "bytes32",
305
- "uint16",
306
- "bytes",
307
- ], [
276
+ }
277
+ function encodeAcrossHeader(spokePool, depositor, sendingAssetId, receivingAssetId, amount, isNative) {
278
+ return (0, utils_js_1.encodePacked)(["uint8", "uint8", "address", "address", "address", "bytes32", "uint128"], [
308
279
  (0, utils_js_1.uint8)(ComposerCommands.BRIDGING),
309
280
  (0, utils_js_1.uint8)(BridgeIds.ACROSS),
310
281
  spokePool,
311
282
  depositor,
312
283
  sendingAssetId,
313
284
  receivingAssetId,
314
- (0, utils_js_1.generateAmountBitmap)((0, utils_js_1.uint128)(amount), false, true),
285
+ (0, utils_js_1.generateAmountBitmap)((0, utils_js_1.uint128)(amount), false, isNative),
286
+ ]);
287
+ }
288
+ function encodeAcrossParams(fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message) {
289
+ return (0, utils_js_1.encodePacked)(["uint128", "uint32", "uint32", "uint8", "uint8", "bytes32", "uint32", "uint16", "bytes"], [
315
290
  fixedFee,
316
291
  feePercentage,
317
292
  destinationChainId,
293
+ fromTokenDecimals,
294
+ toTokenDecimals,
318
295
  receiver,
296
+ deadline,
319
297
  (0, utils_js_1.uint16)(message.length / 2 - 1),
320
298
  message,
321
299
  ]);
322
- return bridgeData;
323
300
  }
324
301
  function encodeSquidRouterCall(asset, gateway, bridgedTokenSymbol, amount, destinationChain, destinationAddress, payload, gasRefundRecipient, enableExpress, nativeAmount) {
325
302
  const partialData = encodeSquidRouterCallPartial(asset, gateway, bridgedTokenSymbol, amount, destinationChain, destinationAddress, payload);
@@ -347,6 +324,26 @@ function encodeSquidRouterCallPartial(asset, gateway, bridgedTokenSymbol, amount
347
324
  (0, utils_js_1.uint128)(amount),
348
325
  ]);
349
326
  }
327
+ function encodeGasZipBridge(gasZipRouter, receiver, amount, destinationChainId) {
328
+ return (0, utils_js_1.encodePacked)(["uint8", "uint8", "address", "bytes32", "uint128", "uint256"], [
329
+ (0, utils_js_1.uint8)(ComposerCommands.BRIDGING),
330
+ (0, utils_js_1.uint8)(BridgeIds.GASZIP),
331
+ gasZipRouter,
332
+ receiver,
333
+ (0, utils_js_1.uint128)(amount),
334
+ destinationChainId,
335
+ ]);
336
+ }
337
+ function encodeGasZipEvmBridge(gasZipRouter, receiver, amount, destinationChainId) {
338
+ return (0, utils_js_1.encodePacked)(["uint8", "uint8", "address", "bytes32", "uint128", "uint256"], [
339
+ (0, utils_js_1.uint8)(ComposerCommands.BRIDGING),
340
+ (0, utils_js_1.uint8)(BridgeIds.GASZIP),
341
+ gasZipRouter,
342
+ (0, utils_js_1.rightPadZero)(receiver),
343
+ (0, utils_js_1.uint128)(amount),
344
+ destinationChainId,
345
+ ]);
346
+ }
350
347
  function encodePermit2TransferFrom(token, receiver, amount) {
351
348
  return (0, utils_js_1.encodePacked)(["uint8", "uint8", "address", "address", "uint128"], [(0, utils_js_1.uint8)(ComposerCommands.TRANSFERS), (0, utils_js_1.uint8)(TransferIds.PERMIT2_TRANSFER_FROM), token, receiver, (0, utils_js_1.uint128)(amount)]);
352
349
  }
package/dist/cjs/utils.js CHANGED
@@ -14,6 +14,7 @@ exports.encodePacked = encodePacked;
14
14
  exports.generateAmountBitmap = generateAmountBitmap;
15
15
  exports.getMorphoCollateral = getMorphoCollateral;
16
16
  exports.getMorphoLoanAsset = getMorphoLoanAsset;
17
+ exports.rightPadZero = rightPadZero;
17
18
  exports.newbytes = newbytes;
18
19
  exports.bytes = bytes;
19
20
  const viem_1 = require("viem");
@@ -69,6 +70,9 @@ function getMorphoLoanAsset(market) {
69
70
  const slice = market.slice(2, 42);
70
71
  return `0x${slice}`;
71
72
  }
73
+ function rightPadZero(address) {
74
+ return (address.toLowerCase() + "0".repeat(24));
75
+ }
72
76
  function newbytes(length) {
73
77
  return ("0x" + "0".repeat(length * 2));
74
78
  }
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
2
  import { zeroAddress } from "viem";
3
- import { encodePacked, uint128, uint8, uint16, uint256, generateAmountBitmap, newbytes, bytes, getMorphoCollateral, getMorphoLoanAsset, } from "./utils.js";
3
+ import { encodePacked, uint128, uint8, uint16, uint256, generateAmountBitmap, newbytes, bytes, getMorphoCollateral, getMorphoLoanAsset, rightPadZero, } from "./utils.js";
4
4
  export var SweepType;
5
5
  (function (SweepType) {
6
6
  SweepType[SweepType["VALIDATE"] = 0] = "VALIDATE";
@@ -95,6 +95,7 @@ export var BridgeIds;
95
95
  BridgeIds[BridgeIds["STARGATE_V2"] = 0] = "STARGATE_V2";
96
96
  BridgeIds[BridgeIds["ACROSS"] = 10] = "ACROSS";
97
97
  BridgeIds[BridgeIds["SQUID_ROUTER"] = 20] = "SQUID_ROUTER";
98
+ BridgeIds[BridgeIds["GASZIP"] = 30] = "GASZIP";
98
99
  })(BridgeIds || (BridgeIds = {}));
99
100
  export var DexTypeMappings;
100
101
  (function (DexTypeMappings) {
@@ -182,69 +183,41 @@ export function encodeStargateV2BridgeSimpleTaxi(asset, stargatePool, dstEid, re
182
183
  export function encodeStargateV2BridgeSimpleBus(asset, stargatePool, dstEid, receiver, refundReceiver, amount, isNative, slippage, fee) {
183
184
  return encodeStargateV2Bridge(asset, stargatePool, dstEid, receiver, refundReceiver, amount, slippage, fee, true, isNative, newbytes(0), newbytes(0));
184
185
  }
185
- export function encodeAcrossBridgeToken(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, receiver, message) {
186
- const bridgeData = encodePacked([
187
- "uint8",
188
- "uint8",
189
- "address",
190
- "address",
191
- "address",
192
- "bytes32",
193
- "uint128",
194
- "uint128",
195
- "uint32",
196
- "uint32",
197
- "bytes32",
198
- "uint16",
199
- "bytes",
200
- ], [
201
- uint8(ComposerCommands.BRIDGING),
202
- uint8(BridgeIds.ACROSS),
203
- spokePool,
204
- depositor,
205
- sendingAssetId,
206
- receivingAssetId,
207
- generateAmountBitmap(uint128(amount), false, false),
208
- fixedFee,
209
- feePercentage,
210
- destinationChainId,
211
- receiver,
212
- uint16(message.length / 2 - 1),
213
- message,
186
+ export function encodeAcrossBridgeToken(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message) {
187
+ return encodePacked(["bytes", "bytes"], [
188
+ encodeAcrossHeader(spokePool, depositor, sendingAssetId, receivingAssetId, amount, false),
189
+ encodeAcrossParams(fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message),
190
+ ]);
191
+ }
192
+ export function encodeAcrossBridgeNative(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message) {
193
+ return encodePacked(["bytes", "bytes"], [
194
+ encodeAcrossHeader(spokePool, depositor, sendingAssetId, receivingAssetId, amount, true),
195
+ encodeAcrossParams(fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message),
214
196
  ]);
215
- return bridgeData;
216
- }
217
- export function encodeAcrossBridgeNative(spokePool, depositor, sendingAssetId, receivingAssetId, amount, fixedFee, feePercentage, destinationChainId, receiver, message) {
218
- const bridgeData = encodePacked([
219
- "uint8",
220
- "uint8",
221
- "address",
222
- "address",
223
- "address",
224
- "bytes32",
225
- "uint128",
226
- "uint128",
227
- "uint32",
228
- "uint32",
229
- "bytes32",
230
- "uint16",
231
- "bytes",
232
- ], [
197
+ }
198
+ export function encodeAcrossHeader(spokePool, depositor, sendingAssetId, receivingAssetId, amount, isNative) {
199
+ return encodePacked(["uint8", "uint8", "address", "address", "address", "bytes32", "uint128"], [
233
200
  uint8(ComposerCommands.BRIDGING),
234
201
  uint8(BridgeIds.ACROSS),
235
202
  spokePool,
236
203
  depositor,
237
204
  sendingAssetId,
238
205
  receivingAssetId,
239
- generateAmountBitmap(uint128(amount), false, true),
206
+ generateAmountBitmap(uint128(amount), false, isNative),
207
+ ]);
208
+ }
209
+ export function encodeAcrossParams(fixedFee, feePercentage, destinationChainId, fromTokenDecimals, toTokenDecimals, receiver, deadline, message) {
210
+ return encodePacked(["uint128", "uint32", "uint32", "uint8", "uint8", "bytes32", "uint32", "uint16", "bytes"], [
240
211
  fixedFee,
241
212
  feePercentage,
242
213
  destinationChainId,
214
+ fromTokenDecimals,
215
+ toTokenDecimals,
243
216
  receiver,
217
+ deadline,
244
218
  uint16(message.length / 2 - 1),
245
219
  message,
246
220
  ]);
247
- return bridgeData;
248
221
  }
249
222
  export function encodeSquidRouterCall(asset, gateway, bridgedTokenSymbol, amount, destinationChain, destinationAddress, payload, gasRefundRecipient, enableExpress, nativeAmount) {
250
223
  const partialData = encodeSquidRouterCallPartial(asset, gateway, bridgedTokenSymbol, amount, destinationChain, destinationAddress, payload);
@@ -272,6 +245,26 @@ export function encodeSquidRouterCallPartial(asset, gateway, bridgedTokenSymbol,
272
245
  uint128(amount),
273
246
  ]);
274
247
  }
248
+ export function encodeGasZipBridge(gasZipRouter, receiver, amount, destinationChainId) {
249
+ return encodePacked(["uint8", "uint8", "address", "bytes32", "uint128", "uint256"], [
250
+ uint8(ComposerCommands.BRIDGING),
251
+ uint8(BridgeIds.GASZIP),
252
+ gasZipRouter,
253
+ receiver,
254
+ uint128(amount),
255
+ destinationChainId,
256
+ ]);
257
+ }
258
+ export function encodeGasZipEvmBridge(gasZipRouter, receiver, amount, destinationChainId) {
259
+ return encodePacked(["uint8", "uint8", "address", "bytes32", "uint128", "uint256"], [
260
+ uint8(ComposerCommands.BRIDGING),
261
+ uint8(BridgeIds.GASZIP),
262
+ gasZipRouter,
263
+ rightPadZero(receiver),
264
+ uint128(amount),
265
+ destinationChainId,
266
+ ]);
267
+ }
275
268
  export function encodePermit2TransferFrom(token, receiver, amount) {
276
269
  return encodePacked(["uint8", "uint8", "address", "address", "uint128"], [uint8(ComposerCommands.TRANSFERS), uint8(TransferIds.PERMIT2_TRANSFER_FROM), token, receiver, uint128(amount)]);
277
270
  }
package/dist/esm/utils.js CHANGED
@@ -51,6 +51,9 @@ export function getMorphoLoanAsset(market) {
51
51
  const slice = market.slice(2, 42);
52
52
  return `0x${slice}`;
53
53
  }
54
+ export function rightPadZero(address) {
55
+ return (address.toLowerCase() + "0".repeat(24));
56
+ }
54
57
  export function newbytes(length) {
55
58
  return ("0x" + "0".repeat(length * 2));
56
59
  }
@@ -79,7 +79,8 @@ export declare enum ComposerCommands {
79
79
  export declare enum BridgeIds {
80
80
  STARGATE_V2 = 0,
81
81
  ACROSS = 10,
82
- SQUID_ROUTER = 20
82
+ SQUID_ROUTER = 20,
83
+ GASZIP = 30
83
84
  }
84
85
  export declare enum DexTypeMappings {
85
86
  UNISWAP_V3_ID = 0,
@@ -117,10 +118,14 @@ export declare function encodePermit(permitId: bigint, target: Address, data: He
117
118
  export declare function encodeStargateV2BridgePartial(amount: bigint, slippage: number, fee: bigint, isBusMode: boolean, isNative: boolean, composeMsg: Hex, extraOptions: Hex): Hex;
118
119
  export declare function encodeStargateV2BridgeSimpleTaxi(asset: Address, stargatePool: Address, dstEid: number, receiver: Hex, refundReceiver: Address, amount: bigint, isNative: boolean, slippage: number, fee: bigint): Hex;
119
120
  export declare function encodeStargateV2BridgeSimpleBus(asset: Address, stargatePool: Address, dstEid: number, receiver: Hex, refundReceiver: Address, amount: bigint, isNative: boolean, slippage: number, fee: bigint): Hex;
120
- export declare function encodeAcrossBridgeToken(spokePool: Address, depositor: Address, sendingAssetId: Address, receivingAssetId: Hex, amount: bigint, fixedFee: bigint, feePercentage: number, destinationChainId: number, receiver: Hex, message: Hex): Hex;
121
- export declare function encodeAcrossBridgeNative(spokePool: Address, depositor: Address, sendingAssetId: Address, receivingAssetId: Hex, amount: bigint, fixedFee: bigint, feePercentage: number, destinationChainId: number, receiver: Hex, message: Hex): Hex;
121
+ export declare function encodeAcrossBridgeToken(spokePool: Address, depositor: Address, sendingAssetId: Address, receivingAssetId: Hex, amount: bigint, fixedFee: bigint, feePercentage: number, destinationChainId: number, fromTokenDecimals: number, toTokenDecimals: number, receiver: Hex, deadline: number, message: Hex): Hex;
122
+ export declare function encodeAcrossBridgeNative(spokePool: Address, depositor: Address, sendingAssetId: Address, receivingAssetId: Hex, amount: bigint, fixedFee: bigint, feePercentage: number, destinationChainId: number, fromTokenDecimals: number, toTokenDecimals: number, receiver: Hex, deadline: number, message: Hex): Hex;
123
+ export declare function encodeAcrossHeader(spokePool: Address, depositor: Address, sendingAssetId: Address, receivingAssetId: Hex, amount: bigint, isNative: boolean): Hex;
124
+ export declare function encodeAcrossParams(fixedFee: bigint, feePercentage: number, destinationChainId: number, fromTokenDecimals: number, toTokenDecimals: number, receiver: Hex, deadline: number, message: Hex): Hex;
122
125
  export declare function encodeSquidRouterCall(asset: Address, gateway: Address, bridgedTokenSymbol: Hex, amount: bigint, destinationChain: Hex, destinationAddress: Hex, payload: Hex, gasRefundRecipient: Address, enableExpress: boolean, nativeAmount: bigint): Hex;
123
126
  export declare function encodeSquidRouterCallPartial(asset: Address, gateway: Address, bridgedTokenSymbol: Hex, amount: bigint, destinationChain: Hex, destinationAddress: Hex, payload: Hex): Hex;
127
+ export declare function encodeGasZipBridge(gasZipRouter: Address, receiver: Hex, amount: bigint, destinationChainId: bigint): Hex;
128
+ export declare function encodeGasZipEvmBridge(gasZipRouter: Address, receiver: Address, amount: bigint, destinationChainId: bigint): Hex;
124
129
  export declare function encodePermit2TransferFrom(token: Address, receiver: Address, amount: bigint): Hex;
125
130
  export declare function encodeNextGenDexUnlock(singleton: Address, id: bigint, d: Hex): Hex;
126
131
  export declare function encodeBalancerV3FlashLoan(singleton: Address, poolId: bigint, asset: Address, receiver: Address, amount: bigint, flashData: Hex): Hex;
@@ -15,5 +15,6 @@ export declare function encodePacked(types: string[], values: any[]): Hex;
15
15
  export declare function generateAmountBitmap(amount: bigint, useShares: boolean, native: boolean): bigint;
16
16
  export declare function getMorphoCollateral(market: Hex): Address;
17
17
  export declare function getMorphoLoanAsset(market: Hex): Address;
18
+ export declare function rightPadZero(address: Address): Hex;
18
19
  export declare function newbytes(length: number): Hex;
19
20
  export declare function bytes(value: Hex): Hex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1delta/calldatalib",
3
- "version": "0.0.39",
3
+ "version": "0.0.42",
4
4
  "description": "Generated CalldataLib TypeScript functions for 1delta smart contracts",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",