@dzapio/sdk 2.0.39 → 2.0.41

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/index.d.mts CHANGED
@@ -719,7 +719,6 @@ type TradeBuildTxnRequestData = {
719
719
  slippage: number;
720
720
  additionalInfo?: AdditionalInfo;
721
721
  permitData?: string;
722
- permit?: TokenPermitData;
723
722
  };
724
723
  type ParamQuotes = {
725
724
  additionalInfo?: Record<string, unknown>;
@@ -754,7 +753,19 @@ type BtclnTxData = {
754
753
  paymentRequest: string;
755
754
  paymentExpiry: number;
756
755
  };
757
- type TxData = EvmTxData | SvmTxData | BtcTxData | BtclnTxData;
756
+ type HyperLiquidSignTypedData<M extends Record<string, unknown> = Record<string, unknown>> = {
757
+ domain: TypedDataDomain;
758
+ types: Record<string, {
759
+ name: string;
760
+ type: string;
761
+ }[]>;
762
+ primaryType: string;
763
+ message: M;
764
+ };
765
+ type HyperLiquidTxData = {
766
+ signTypedData: HyperLiquidSignTypedData[];
767
+ };
768
+ type TxData = EvmTxData | SvmTxData | BtcTxData | BtclnTxData | HyperLiquidTxData;
758
769
  type TxRequestData<T> = {
759
770
  status: typeof STATUS.success;
760
771
  txId: string;
@@ -900,7 +911,7 @@ type SignatureParamsBase = {
900
911
  type GasSignatureParams = SignatureParamsBase & {
901
912
  gasless: false;
902
913
  };
903
- type SignPermitResponse = {
914
+ type PermitSingleResponse = {
904
915
  status: TxnStatus.success;
905
916
  code: StatusCodes;
906
917
  tokens: {
@@ -909,17 +920,27 @@ type SignPermitResponse = {
909
920
  amount: string;
910
921
  }[];
911
922
  permitType: PermitMode;
912
- } | {
923
+ };
924
+ type PermitBatchResponse = {
913
925
  status: TxnStatus.success;
914
926
  code: StatusCodes;
915
927
  batchPermitData: HexString;
916
928
  permitType: typeof PermitTypes.PermitBatchWitnessTransferFrom;
917
- } | {
929
+ };
930
+ type PermitErrorResponse = {
918
931
  status: Exclude<TxnStatus, typeof TxnStatus.success>;
919
932
  code: StatusCodes;
920
933
  permitType: PermitMode;
921
934
  };
922
- type BroadcastTxData = string;
935
+ type SignPermitResponse<T extends PermitMode = PermitMode> = T extends typeof PermitTypes.AutoPermit ? PermitSingleResponse | PermitBatchResponse | PermitErrorResponse : T extends typeof PermitTypes.PermitBatchWitnessTransferFrom ? PermitBatchResponse | PermitErrorResponse : PermitSingleResponse | PermitErrorResponse;
936
+ type HyperLiquidBroadcastTxData = {
937
+ message: Record<string, unknown>;
938
+ primaryType: string;
939
+ signatureChainId: number;
940
+ signature: HexString;
941
+ account: HexString;
942
+ };
943
+ type BroadcastTxData = string | HyperLiquidBroadcastTxData[];
923
944
  type BroadcastTxParams = {
924
945
  txId: string;
925
946
  chainId: number;
@@ -1924,12 +1945,12 @@ declare class DZapClient {
1924
1945
  status: TxnStatus;
1925
1946
  code: StatusCodes;
1926
1947
  }>;
1927
- sign(params: Prettify<Omit<GasSignatureParams, 'spender' | 'permitType' | 'rpcUrls' | 'gasless' | 'contractVersion'> & {
1948
+ sign<T extends PermitMode = PermitMode>(params: Prettify<Omit<GasSignatureParams, 'spender' | 'permitType' | 'rpcUrls' | 'gasless' | 'contractVersion'> & {
1928
1949
  spender?: HexString;
1929
- permitType?: PermitMode;
1950
+ permitType?: T;
1930
1951
  rpcUrls?: string[];
1931
1952
  service: AvailableDZapServices;
1932
- }>): Promise<SignPermitResponse>;
1953
+ }>): Promise<SignPermitResponse<T>>;
1933
1954
  zap({ request, steps, signer, }: {
1934
1955
  request: ZapBuildTxnRequest | ZapBundleRequest;
1935
1956
  signer: WalletClient | Signer;
@@ -2249,7 +2270,7 @@ declare const hyperliquid: {
2249
2270
  };
2250
2271
  };
2251
2272
  ensTlds?: readonly string[] | undefined;
2252
- id: 998;
2273
+ id: 1337;
2253
2274
  name: "Hyperliquid";
2254
2275
  nativeCurrency: {
2255
2276
  readonly name: "HYPE";
@@ -2421,4 +2442,4 @@ declare const citrea: {
2421
2442
  declare const customViemChains: viemChains.Chain[];
2422
2443
  declare const viemChainsById: Record<number, viemChains.Chain>;
2423
2444
 
2424
- export { type AllowanceType, AllowanceTypes, type ApiRpcResponse, type ApprovalMode, ApprovalModes, type BatchPermitCallbackParams, type BtcTxData, type BtclnTxData, type Chain, type ChainData, type ContractErrorResponse, DZapClient, DZapPermitMode, type DZapTransactionResponse, type EvmTxData, type Fee, type FeeDetails, type GaslessTradeBuildTxnResponse, type HexString, OtherAbis, type ParamQuotes, type PermitMode, PermitTypes, type ProviderDetails, type PsbtInput, type PsbtOutput, type QuoteFilter, QuoteFilters, STATUS, type SVMTxnDetails, Services, type SignPermitResponse, type SignatureCallbackParams, SignatureExpiryInSecs, type SinglePermitCallbackParams, StatusCodes, type StepAction, type SvmTxData, type SwapInfo, SwapInputDataDecoder, type Token, type TokenInfo, type TokenPermitData, type TokenResponse, type TradeBuildTxnRequest, type TradeBuildTxnRequestData, type TradeBuildTxnResponse, type TradeGasBuildTxnResponse, type TradePath, type TradeQuotesRequest, type TradeQuotesRequestData, type TradeQuotesResponse, type TradeStatusResponse, type TradeStep, TxnStatus, type ZapBuildTxnRequest, type ZapBuildTxnResponse, type ZapBundleAction, type ZapBundleRequest, type ZapBundleSrcToken, type ZapBvmTxnDetails, type ZapChains, type ZapEvmTxnDetails, type ZapFee, type ZapIntegratorConfig, type ZapPath, type ZapPathAction, type ZapPathAsset, type ZapPool, type ZapPoolDetails, type ZapPoolDetailsRequest, type ZapPoolsRequest, type ZapPoolsResponse, type ZapPosition, type ZapPositionsRequest, type ZapPositionsResponse, type ZapProviders, type ZapQuoteRequest, type ZapQuoteResponse, type ZapRouteRequestPoolDetails, type ZapRouteRequestPositionDetails, type ZapStatus, type ZapStatusAsset, type ZapStatusRequest, type ZapStatusResponse, type ZapStatusStep, type ZapStep, type ZapTransactionStep, type ZapTxnDetails, type ZapUnderlyingToken, type ZapUnderlyingTokenWithAmount, arthera, astralisTestnet, checkEIP2612PermitSupport, citrea, classifyAddress, contractErrorActions, customViemChains, erc20Functions, extendViemChain, fiveIre, formatToken, getTokensPairKey, hemi, hyperEvm, hyperliquid, pushTestnet, stableChain, tempo, viemChainsById, zapPathAction, zapStepAction };
2445
+ export { type AllowanceType, AllowanceTypes, type ApiRpcResponse, type ApprovalMode, ApprovalModes, type BatchPermitCallbackParams, type BtcTxData, type BtclnTxData, type Chain, type ChainData, type ContractErrorResponse, DZapClient, DZapPermitMode, type DZapTransactionResponse, type EvmTxData, type Fee, type FeeDetails, type GaslessTradeBuildTxnResponse, type HexString, type HyperLiquidTxData, OtherAbis, type ParamQuotes, type PermitMode, PermitTypes, type ProviderDetails, type PsbtInput, type PsbtOutput, type QuoteFilter, QuoteFilters, STATUS, type SVMTxnDetails, Services, type SignPermitResponse, type SignatureCallbackParams, SignatureExpiryInSecs, type SinglePermitCallbackParams, StatusCodes, type StepAction, type SvmTxData, type SwapInfo, SwapInputDataDecoder, type Token, type TokenInfo, type TokenPermitData, type TokenResponse, type TradeBuildTxnRequest, type TradeBuildTxnRequestData, type TradeBuildTxnResponse, type TradeGasBuildTxnResponse, type TradePath, type TradeQuotesRequest, type TradeQuotesRequestData, type TradeQuotesResponse, type TradeStatusResponse, type TradeStep, TxnStatus, type ZapBuildTxnRequest, type ZapBuildTxnResponse, type ZapBundleAction, type ZapBundleRequest, type ZapBundleSrcToken, type ZapBvmTxnDetails, type ZapChains, type ZapEvmTxnDetails, type ZapFee, type ZapIntegratorConfig, type ZapPath, type ZapPathAction, type ZapPathAsset, type ZapPool, type ZapPoolDetails, type ZapPoolDetailsRequest, type ZapPoolsRequest, type ZapPoolsResponse, type ZapPosition, type ZapPositionsRequest, type ZapPositionsResponse, type ZapProviders, type ZapQuoteRequest, type ZapQuoteResponse, type ZapRouteRequestPoolDetails, type ZapRouteRequestPositionDetails, type ZapStatus, type ZapStatusAsset, type ZapStatusRequest, type ZapStatusResponse, type ZapStatusStep, type ZapStep, type ZapTransactionStep, type ZapTxnDetails, type ZapUnderlyingToken, type ZapUnderlyingTokenWithAmount, arthera, astralisTestnet, checkEIP2612PermitSupport, citrea, classifyAddress, contractErrorActions, customViemChains, erc20Functions, extendViemChain, fiveIre, formatToken, getTokensPairKey, hemi, hyperEvm, hyperliquid, pushTestnet, stableChain, tempo, viemChainsById, zapPathAction, zapStepAction };
package/dist/index.d.ts CHANGED
@@ -719,7 +719,6 @@ type TradeBuildTxnRequestData = {
719
719
  slippage: number;
720
720
  additionalInfo?: AdditionalInfo;
721
721
  permitData?: string;
722
- permit?: TokenPermitData;
723
722
  };
724
723
  type ParamQuotes = {
725
724
  additionalInfo?: Record<string, unknown>;
@@ -754,7 +753,19 @@ type BtclnTxData = {
754
753
  paymentRequest: string;
755
754
  paymentExpiry: number;
756
755
  };
757
- type TxData = EvmTxData | SvmTxData | BtcTxData | BtclnTxData;
756
+ type HyperLiquidSignTypedData<M extends Record<string, unknown> = Record<string, unknown>> = {
757
+ domain: TypedDataDomain;
758
+ types: Record<string, {
759
+ name: string;
760
+ type: string;
761
+ }[]>;
762
+ primaryType: string;
763
+ message: M;
764
+ };
765
+ type HyperLiquidTxData = {
766
+ signTypedData: HyperLiquidSignTypedData[];
767
+ };
768
+ type TxData = EvmTxData | SvmTxData | BtcTxData | BtclnTxData | HyperLiquidTxData;
758
769
  type TxRequestData<T> = {
759
770
  status: typeof STATUS.success;
760
771
  txId: string;
@@ -900,7 +911,7 @@ type SignatureParamsBase = {
900
911
  type GasSignatureParams = SignatureParamsBase & {
901
912
  gasless: false;
902
913
  };
903
- type SignPermitResponse = {
914
+ type PermitSingleResponse = {
904
915
  status: TxnStatus.success;
905
916
  code: StatusCodes;
906
917
  tokens: {
@@ -909,17 +920,27 @@ type SignPermitResponse = {
909
920
  amount: string;
910
921
  }[];
911
922
  permitType: PermitMode;
912
- } | {
923
+ };
924
+ type PermitBatchResponse = {
913
925
  status: TxnStatus.success;
914
926
  code: StatusCodes;
915
927
  batchPermitData: HexString;
916
928
  permitType: typeof PermitTypes.PermitBatchWitnessTransferFrom;
917
- } | {
929
+ };
930
+ type PermitErrorResponse = {
918
931
  status: Exclude<TxnStatus, typeof TxnStatus.success>;
919
932
  code: StatusCodes;
920
933
  permitType: PermitMode;
921
934
  };
922
- type BroadcastTxData = string;
935
+ type SignPermitResponse<T extends PermitMode = PermitMode> = T extends typeof PermitTypes.AutoPermit ? PermitSingleResponse | PermitBatchResponse | PermitErrorResponse : T extends typeof PermitTypes.PermitBatchWitnessTransferFrom ? PermitBatchResponse | PermitErrorResponse : PermitSingleResponse | PermitErrorResponse;
936
+ type HyperLiquidBroadcastTxData = {
937
+ message: Record<string, unknown>;
938
+ primaryType: string;
939
+ signatureChainId: number;
940
+ signature: HexString;
941
+ account: HexString;
942
+ };
943
+ type BroadcastTxData = string | HyperLiquidBroadcastTxData[];
923
944
  type BroadcastTxParams = {
924
945
  txId: string;
925
946
  chainId: number;
@@ -1924,12 +1945,12 @@ declare class DZapClient {
1924
1945
  status: TxnStatus;
1925
1946
  code: StatusCodes;
1926
1947
  }>;
1927
- sign(params: Prettify<Omit<GasSignatureParams, 'spender' | 'permitType' | 'rpcUrls' | 'gasless' | 'contractVersion'> & {
1948
+ sign<T extends PermitMode = PermitMode>(params: Prettify<Omit<GasSignatureParams, 'spender' | 'permitType' | 'rpcUrls' | 'gasless' | 'contractVersion'> & {
1928
1949
  spender?: HexString;
1929
- permitType?: PermitMode;
1950
+ permitType?: T;
1930
1951
  rpcUrls?: string[];
1931
1952
  service: AvailableDZapServices;
1932
- }>): Promise<SignPermitResponse>;
1953
+ }>): Promise<SignPermitResponse<T>>;
1933
1954
  zap({ request, steps, signer, }: {
1934
1955
  request: ZapBuildTxnRequest | ZapBundleRequest;
1935
1956
  signer: WalletClient | Signer;
@@ -2249,7 +2270,7 @@ declare const hyperliquid: {
2249
2270
  };
2250
2271
  };
2251
2272
  ensTlds?: readonly string[] | undefined;
2252
- id: 998;
2273
+ id: 1337;
2253
2274
  name: "Hyperliquid";
2254
2275
  nativeCurrency: {
2255
2276
  readonly name: "HYPE";
@@ -2421,4 +2442,4 @@ declare const citrea: {
2421
2442
  declare const customViemChains: viemChains.Chain[];
2422
2443
  declare const viemChainsById: Record<number, viemChains.Chain>;
2423
2444
 
2424
- export { type AllowanceType, AllowanceTypes, type ApiRpcResponse, type ApprovalMode, ApprovalModes, type BatchPermitCallbackParams, type BtcTxData, type BtclnTxData, type Chain, type ChainData, type ContractErrorResponse, DZapClient, DZapPermitMode, type DZapTransactionResponse, type EvmTxData, type Fee, type FeeDetails, type GaslessTradeBuildTxnResponse, type HexString, OtherAbis, type ParamQuotes, type PermitMode, PermitTypes, type ProviderDetails, type PsbtInput, type PsbtOutput, type QuoteFilter, QuoteFilters, STATUS, type SVMTxnDetails, Services, type SignPermitResponse, type SignatureCallbackParams, SignatureExpiryInSecs, type SinglePermitCallbackParams, StatusCodes, type StepAction, type SvmTxData, type SwapInfo, SwapInputDataDecoder, type Token, type TokenInfo, type TokenPermitData, type TokenResponse, type TradeBuildTxnRequest, type TradeBuildTxnRequestData, type TradeBuildTxnResponse, type TradeGasBuildTxnResponse, type TradePath, type TradeQuotesRequest, type TradeQuotesRequestData, type TradeQuotesResponse, type TradeStatusResponse, type TradeStep, TxnStatus, type ZapBuildTxnRequest, type ZapBuildTxnResponse, type ZapBundleAction, type ZapBundleRequest, type ZapBundleSrcToken, type ZapBvmTxnDetails, type ZapChains, type ZapEvmTxnDetails, type ZapFee, type ZapIntegratorConfig, type ZapPath, type ZapPathAction, type ZapPathAsset, type ZapPool, type ZapPoolDetails, type ZapPoolDetailsRequest, type ZapPoolsRequest, type ZapPoolsResponse, type ZapPosition, type ZapPositionsRequest, type ZapPositionsResponse, type ZapProviders, type ZapQuoteRequest, type ZapQuoteResponse, type ZapRouteRequestPoolDetails, type ZapRouteRequestPositionDetails, type ZapStatus, type ZapStatusAsset, type ZapStatusRequest, type ZapStatusResponse, type ZapStatusStep, type ZapStep, type ZapTransactionStep, type ZapTxnDetails, type ZapUnderlyingToken, type ZapUnderlyingTokenWithAmount, arthera, astralisTestnet, checkEIP2612PermitSupport, citrea, classifyAddress, contractErrorActions, customViemChains, erc20Functions, extendViemChain, fiveIre, formatToken, getTokensPairKey, hemi, hyperEvm, hyperliquid, pushTestnet, stableChain, tempo, viemChainsById, zapPathAction, zapStepAction };
2445
+ export { type AllowanceType, AllowanceTypes, type ApiRpcResponse, type ApprovalMode, ApprovalModes, type BatchPermitCallbackParams, type BtcTxData, type BtclnTxData, type Chain, type ChainData, type ContractErrorResponse, DZapClient, DZapPermitMode, type DZapTransactionResponse, type EvmTxData, type Fee, type FeeDetails, type GaslessTradeBuildTxnResponse, type HexString, type HyperLiquidTxData, OtherAbis, type ParamQuotes, type PermitMode, PermitTypes, type ProviderDetails, type PsbtInput, type PsbtOutput, type QuoteFilter, QuoteFilters, STATUS, type SVMTxnDetails, Services, type SignPermitResponse, type SignatureCallbackParams, SignatureExpiryInSecs, type SinglePermitCallbackParams, StatusCodes, type StepAction, type SvmTxData, type SwapInfo, SwapInputDataDecoder, type Token, type TokenInfo, type TokenPermitData, type TokenResponse, type TradeBuildTxnRequest, type TradeBuildTxnRequestData, type TradeBuildTxnResponse, type TradeGasBuildTxnResponse, type TradePath, type TradeQuotesRequest, type TradeQuotesRequestData, type TradeQuotesResponse, type TradeStatusResponse, type TradeStep, TxnStatus, type ZapBuildTxnRequest, type ZapBuildTxnResponse, type ZapBundleAction, type ZapBundleRequest, type ZapBundleSrcToken, type ZapBvmTxnDetails, type ZapChains, type ZapEvmTxnDetails, type ZapFee, type ZapIntegratorConfig, type ZapPath, type ZapPathAction, type ZapPathAsset, type ZapPool, type ZapPoolDetails, type ZapPoolDetailsRequest, type ZapPoolsRequest, type ZapPoolsResponse, type ZapPosition, type ZapPositionsRequest, type ZapPositionsResponse, type ZapProviders, type ZapQuoteRequest, type ZapQuoteResponse, type ZapRouteRequestPoolDetails, type ZapRouteRequestPositionDetails, type ZapStatus, type ZapStatusAsset, type ZapStatusRequest, type ZapStatusResponse, type ZapStatusStep, type ZapStep, type ZapTransactionStep, type ZapTxnDetails, type ZapUnderlyingToken, type ZapUnderlyingTokenWithAmount, arthera, astralisTestnet, checkEIP2612PermitSupport, citrea, classifyAddress, contractErrorActions, customViemChains, erc20Functions, extendViemChain, fiveIre, formatToken, getTokensPairKey, hemi, hyperEvm, hyperliquid, pushTestnet, stableChain, tempo, viemChainsById, zapPathAction, zapStepAction };
package/dist/index.js CHANGED
@@ -765,7 +765,9 @@ var DZapPriceProvider = class {
765
765
  this.requiresChainConfig = false;
766
766
  this.fetchPrices = async (chainId, tokenAddresses) => {
767
767
  try {
768
- const tokenPrices = await fetchTokenPrice(tokenAddresses, chainId);
768
+ if (tokenAddresses.length === 0) return {};
769
+ const tokens = tokenAddresses.join(",");
770
+ const tokenPrices = await fetchTokenPrice(tokens, chainId);
769
771
  return tokenPrices;
770
772
  } catch (e) {
771
773
  console.error("Failed to fetch token price", e);
@@ -10723,7 +10725,7 @@ var hyperEvm = /* @__PURE__ */ viem.defineChain({
10723
10725
  }
10724
10726
  });
10725
10727
  var hyperliquid = /* @__PURE__ */ viem.defineChain({
10726
- id: 998,
10728
+ id: 1337,
10727
10729
  name: "Hyperliquid",
10728
10730
  nativeCurrency: { name: "HYPE", symbol: "HYPE", decimals: 18 },
10729
10731
  contracts: {
@@ -12884,7 +12886,7 @@ var exclusiveChainIds = {
12884
12886
  abstract: 2741,
12885
12887
  lens: 232,
12886
12888
  citreaTestnet: 5115,
12887
- hyperLiquid: 998,
12889
+ hyperLiquid: 1337,
12888
12890
  citrea: 4114,
12889
12891
  pushTestnet: 42101,
12890
12892
  astralisTestnet: 71261,
@@ -14278,6 +14280,97 @@ var getPermit2Signature = async (params) => {
14278
14280
 
14279
14281
  // src/transactionHandlers/permit.ts
14280
14282
  var _PermitTxnHandler = class _PermitTxnHandler {
14283
+ static async signPermit(signPermitReq) {
14284
+ const { tokens } = signPermitReq;
14285
+ if (tokens.length === 0) {
14286
+ if (signPermitReq.permitType === PermitTypes.PermitBatchWitnessTransferFrom) {
14287
+ return {
14288
+ status: "success" /* success */,
14289
+ code: 200 /* Success */,
14290
+ batchPermitData: DEFAULT_PERMIT2_DATA,
14291
+ permitType: PermitTypes.PermitBatchWitnessTransferFrom
14292
+ };
14293
+ }
14294
+ return { status: "success" /* success */, code: 200 /* Success */, tokens, permitType: signPermitReq.permitType };
14295
+ }
14296
+ const oneToMany = tokens.length > 1 && isOneToMany(tokens[0].address, tokens[1].address);
14297
+ const shouldUseBatchPermit = _PermitTxnHandler.shouldUseBatchPermit({
14298
+ permitType: signPermitReq.permitType,
14299
+ isBatchPermitAllowed: signPermitReq.isBatchPermitAllowed,
14300
+ tokens,
14301
+ oneToMany,
14302
+ contractVersion: signPermitReq.contractVersion,
14303
+ service: signPermitReq.service
14304
+ });
14305
+ if (shouldUseBatchPermit) {
14306
+ const resp = await _PermitTxnHandler.generateBatchPermitDataForTokens({
14307
+ ...signPermitReq,
14308
+ tokens: tokens.map((token, index) => ({ ...token, index })),
14309
+ account: signPermitReq.sender,
14310
+ permitType: PermitTypes.PermitBatchWitnessTransferFrom
14311
+ //override because only PermitBatchWitnessTransferFrom supports batch
14312
+ });
14313
+ if (resp.status !== "success" /* success */) {
14314
+ return { status: resp.status, code: resp.code, permitType: PermitTypes.PermitBatchWitnessTransferFrom };
14315
+ }
14316
+ if (signPermitReq.signatureCallback) {
14317
+ await signPermitReq.signatureCallback({
14318
+ batchPermitData: resp.permitData,
14319
+ tokens,
14320
+ permitType: resp.permitType
14321
+ });
14322
+ }
14323
+ return {
14324
+ status: "success" /* success */,
14325
+ code: 200 /* Success */,
14326
+ batchPermitData: resp.permitData,
14327
+ permitType: resp.permitType
14328
+ };
14329
+ } else {
14330
+ if (signPermitReq.permitType === PermitTypes.PermitBatchWitnessTransferFrom) {
14331
+ return { status: "error" /* error */, code: 500 /* Error */, permitType: PermitTypes.PermitBatchWitnessTransferFrom };
14332
+ }
14333
+ const totalSrcAmount = calcTotalSrcTokenAmount(tokens);
14334
+ let firstTokenNonce = null;
14335
+ let permitType = _PermitTxnHandler.v1PermitSupport({
14336
+ contractVersion: signPermitReq.contractVersion,
14337
+ service: signPermitReq.service
14338
+ }) ? PermitTypes.PermitSingle : signPermitReq.permitType;
14339
+ for (let dataIdx = 0; dataIdx < tokens.length; dataIdx++) {
14340
+ const isFirstToken = dataIdx === 0;
14341
+ const res = await _PermitTxnHandler.generatePermitDataForToken({
14342
+ ...signPermitReq,
14343
+ token: {
14344
+ ...tokens[dataIdx],
14345
+ index: dataIdx
14346
+ },
14347
+ firstTokenNonce: firstTokenNonce ?? void 0,
14348
+ oneToMany,
14349
+ totalSrcAmount,
14350
+ account: signPermitReq.sender,
14351
+ permitType
14352
+ });
14353
+ permitType = res.permitType;
14354
+ if (res.status !== "success" /* success */) {
14355
+ return { status: res.status, code: res.code, permitType: res.permitType };
14356
+ }
14357
+ tokens[dataIdx].permitData = res.permitData;
14358
+ if (isFirstToken && !isDZapNativeToken(tokens[dataIdx].address)) {
14359
+ firstTokenNonce = res.nonce ?? null;
14360
+ }
14361
+ if (signPermitReq.signatureCallback && !isDZapNativeToken(tokens[dataIdx].address)) {
14362
+ const amount = oneToMany && isFirstToken ? totalSrcAmount : BigInt(tokens[dataIdx].amount);
14363
+ await signPermitReq.signatureCallback({
14364
+ permitData: res.permitData,
14365
+ srcToken: tokens[dataIdx].address,
14366
+ amount: amount.toString(),
14367
+ permitType: res.permitType
14368
+ });
14369
+ }
14370
+ }
14371
+ return { status: "success" /* success */, tokens, code: 200 /* Success */, permitType };
14372
+ }
14373
+ }
14281
14374
  };
14282
14375
  _PermitTxnHandler.generateBatchPermitDataForTokens = async (params) => {
14283
14376
  const resp = await getPermit2Signature(params);
@@ -14414,83 +14507,6 @@ _PermitTxnHandler.shouldUseBatchPermit = ({
14414
14507
  const isContractSupport = !_PermitTxnHandler.v1PermitSupport({ contractVersion, service });
14415
14508
  return isBatchPermitAllowed && (isBatchPermitRequested || shouldAutoBatch) && isContractSupport;
14416
14509
  };
14417
- _PermitTxnHandler.signPermit = async (signPermitReq) => {
14418
- const { tokens } = signPermitReq;
14419
- if (tokens.length === 0) {
14420
- return { status: "success" /* success */, code: 200 /* Success */, tokens, permitType: signPermitReq.permitType };
14421
- }
14422
- const oneToMany = tokens.length > 1 && isOneToMany(tokens[0].address, tokens[1].address);
14423
- const shouldUseBatchPermit = _PermitTxnHandler.shouldUseBatchPermit({
14424
- permitType: signPermitReq.permitType,
14425
- isBatchPermitAllowed: signPermitReq.isBatchPermitAllowed,
14426
- tokens,
14427
- oneToMany,
14428
- contractVersion: signPermitReq.contractVersion,
14429
- service: signPermitReq.service
14430
- });
14431
- if (shouldUseBatchPermit) {
14432
- const resp = await _PermitTxnHandler.generateBatchPermitDataForTokens({
14433
- ...signPermitReq,
14434
- tokens: tokens.map((token, index) => ({ ...token, index })),
14435
- account: signPermitReq.sender,
14436
- permitType: PermitTypes.PermitBatchWitnessTransferFrom
14437
- //override because only PermitBatchWitnessTransferFrom supports batch
14438
- });
14439
- if (resp.status !== "success" /* success */) {
14440
- return { status: resp.status, code: resp.code, permitType: PermitTypes.PermitBatchWitnessTransferFrom };
14441
- }
14442
- if (signPermitReq.signatureCallback) {
14443
- await signPermitReq.signatureCallback({
14444
- batchPermitData: resp.permitData,
14445
- tokens,
14446
- permitType: resp.permitType
14447
- });
14448
- }
14449
- return {
14450
- status: "success" /* success */,
14451
- code: 200 /* Success */,
14452
- batchPermitData: resp.permitData,
14453
- permitType: resp.permitType
14454
- };
14455
- } else {
14456
- const totalSrcAmount = calcTotalSrcTokenAmount(tokens);
14457
- let firstTokenNonce = null;
14458
- let permitType = _PermitTxnHandler.v1PermitSupport({ contractVersion: signPermitReq.contractVersion, service: signPermitReq.service }) ? PermitTypes.PermitSingle : signPermitReq.permitType;
14459
- for (let dataIdx = 0; dataIdx < tokens.length; dataIdx++) {
14460
- const isFirstToken = dataIdx === 0;
14461
- const res = await _PermitTxnHandler.generatePermitDataForToken({
14462
- ...signPermitReq,
14463
- token: {
14464
- ...tokens[dataIdx],
14465
- index: dataIdx
14466
- },
14467
- firstTokenNonce: firstTokenNonce ?? void 0,
14468
- oneToMany,
14469
- totalSrcAmount,
14470
- account: signPermitReq.sender,
14471
- permitType
14472
- });
14473
- permitType = res.permitType;
14474
- if (res.status !== "success" /* success */) {
14475
- return { status: res.status, code: res.code, permitType: res.permitType };
14476
- }
14477
- tokens[dataIdx].permitData = res.permitData;
14478
- if (isFirstToken && !isDZapNativeToken(tokens[dataIdx].address)) {
14479
- firstTokenNonce = res.nonce ?? null;
14480
- }
14481
- if (signPermitReq.signatureCallback && !isDZapNativeToken(tokens[dataIdx].address)) {
14482
- const amount = oneToMany && isFirstToken ? totalSrcAmount : BigInt(tokens[dataIdx].amount);
14483
- await signPermitReq.signatureCallback({
14484
- permitData: res.permitData,
14485
- srcToken: tokens[dataIdx].address,
14486
- amount: amount.toString(),
14487
- permitType: res.permitType
14488
- });
14489
- }
14490
- }
14491
- return { status: "success" /* success */, tokens, code: 200 /* Success */, permitType };
14492
- }
14493
- };
14494
14510
  var PermitTxnHandler = _PermitTxnHandler;
14495
14511
  var permit_default = PermitTxnHandler;
14496
14512
  function encodeApproveCallData({ spender, amount }) {
@@ -14753,6 +14769,61 @@ var signCustomTypedData = async (params) => {
14753
14769
  }
14754
14770
  };
14755
14771
 
14772
+ // src/transactionHandlers/hyperliquid.ts
14773
+ var HyperLiquidTxHandler = class {
14774
+ };
14775
+ HyperLiquidTxHandler.sendTransaction = async (signer, account, txnData, chainId, additionalInfo, updatedQuotes) => {
14776
+ var _a;
14777
+ const signTypedData2 = "signTypedData" in txnData.transaction ? txnData.transaction.signTypedData : null;
14778
+ if (!signTypedData2) {
14779
+ return {
14780
+ status: "error" /* error */,
14781
+ errorMsg: "Missing typed data for HyperLiquid transaction",
14782
+ code: 500 /* Error */
14783
+ };
14784
+ }
14785
+ const txData = [];
14786
+ for (let i = 0; i < signTypedData2.length; i++) {
14787
+ const typedData = signTypedData2[i];
14788
+ const [resp, signatureChainId] = await Promise.all([
14789
+ signCustomTypedData({
14790
+ signer,
14791
+ account,
14792
+ domain: typedData.domain,
14793
+ types: typedData.types,
14794
+ message: typedData.message,
14795
+ primaryType: typedData.primaryType
14796
+ }),
14797
+ signer.getChainId()
14798
+ ]);
14799
+ if (resp.status !== "success" /* success */ || !((_a = resp.data) == null ? void 0 : _a.signature)) {
14800
+ throw new Error("Failed to sign transaction");
14801
+ }
14802
+ txData.push({
14803
+ primaryType: typedData.primaryType,
14804
+ message: typedData.message,
14805
+ signature: resp.data.signature,
14806
+ account,
14807
+ signatureChainId
14808
+ });
14809
+ }
14810
+ const txResp = await broadcastTradeTx({
14811
+ chainId,
14812
+ txData,
14813
+ txId: txnData.txId
14814
+ });
14815
+ if (txResp.status !== "success" /* success */) {
14816
+ throw new Error("Failed to broadcast or save transaction");
14817
+ }
14818
+ return {
14819
+ status: "success" /* success */,
14820
+ code: 200 /* Success */,
14821
+ txnHash: txResp.txnHash,
14822
+ additionalInfo,
14823
+ updatedQuotes
14824
+ };
14825
+ };
14826
+
14756
14827
  // src/transactionHandlers/trade.ts
14757
14828
  var _TradeTxnHandler = class _TradeTxnHandler {
14758
14829
  };
@@ -14826,54 +14897,6 @@ _TradeTxnHandler.sendTxnWithBatch = async (request, signer, txnParams, chainId,
14826
14897
  updatedQuotes
14827
14898
  };
14828
14899
  };
14829
- _TradeTxnHandler.sendHyperLiquidTransaction = async (signer, txnParams, txnData, chainId, additionalInfo, updatedQuotes) => {
14830
- var _a;
14831
- let txnDetails;
14832
- if (chainId === exclusiveChainIds.hyperLiquid) {
14833
- const providerData = additionalInfo ? Object.values(additionalInfo)[0] : null;
14834
- const typedData = providerData && "typedData" in providerData ? providerData.typedData : null;
14835
- if (!additionalInfo || !typedData) {
14836
- return {
14837
- status: "error" /* error */,
14838
- errorMsg: "Missing additional info for HyperLiquid transaction",
14839
- code: 500 /* Error */
14840
- };
14841
- }
14842
- const resp = await signCustomTypedData({
14843
- signer,
14844
- account: txnParams.from,
14845
- domain: typedData.domain,
14846
- types: typedData.types,
14847
- message: typedData.message,
14848
- primaryType: typedData.primaryType
14849
- });
14850
- if (resp.status !== "success" /* success */) {
14851
- throw new Error("Failed to sign transaction");
14852
- }
14853
- txnDetails = (_a = resp.data) == null ? void 0 : _a.signature;
14854
- } else {
14855
- const resp = await _TradeTxnHandler.sendTransaction(signer, txnParams, chainId, additionalInfo, updatedQuotes);
14856
- if (resp.status !== "success" /* success */) {
14857
- throw new Error("Failed to sign transaction");
14858
- }
14859
- txnDetails = resp.txnHash;
14860
- }
14861
- const txResp = await broadcastTradeTx({
14862
- chainId,
14863
- txData: txnDetails,
14864
- txId: txnData.txId
14865
- });
14866
- if (txResp.status !== "success" /* success */) {
14867
- throw new Error("Failed to broadcast or save transaction");
14868
- }
14869
- return {
14870
- status: "success" /* success */,
14871
- code: 200 /* Success */,
14872
- txnHash: txResp.txnHash,
14873
- additionalInfo,
14874
- updatedQuotes
14875
- };
14876
- };
14877
14900
  _TradeTxnHandler.buildAndSendTransaction = async ({
14878
14901
  request,
14879
14902
  signer,
@@ -14893,8 +14916,15 @@ _TradeTxnHandler.buildAndSendTransaction = async ({
14893
14916
  }
14894
14917
  const { data, from, to, value, gasLimit, additionalInfo, updatedQuotes } = buildTxnResponseData;
14895
14918
  const txnParams = { from, to, data, value, gasLimit };
14896
- if ([chainId, ...request.data.map((e) => e.toChain)].some((chain) => chain === exclusiveChainIds.hyperLiquid)) {
14897
- return _TradeTxnHandler.sendHyperLiquidTransaction(signer, txnParams, buildTxnResponseData, chainId, additionalInfo, updatedQuotes);
14919
+ if (chainId === exclusiveChainIds.hyperLiquid) {
14920
+ return HyperLiquidTxHandler.sendTransaction(
14921
+ signer,
14922
+ txnParams.from,
14923
+ buildTxnResponseData,
14924
+ chainId,
14925
+ additionalInfo,
14926
+ updatedQuotes
14927
+ );
14898
14928
  }
14899
14929
  if (batchTransaction && !isTypeSigner(signer)) {
14900
14930
  return _TradeTxnHandler.sendTxnWithBatch(request, signer, txnParams, chainId, additionalInfo, updatedQuotes, multicallAddress, rpcUrls);
@@ -16004,11 +16034,19 @@ var _DZapClient = class _DZapClient {
16004
16034
  * @param params.permitType - Optional permit type (defaults to AutoPermit for optimal compatibility)
16005
16035
  * @param params.signatureCallback - Optional callback function for each completed signature
16006
16036
  * @param params.spender - Optional custom spender address (if not using default DZap contract)
16007
- * @returns Promise resolving to permit signatures and related data
16037
+ * @returns Promise resolving to a {@link SignPermitResponse}, narrowed by the requested `permitType`:
16038
+ * - `AutoPermit` (default): `PermitSingleResponse | PermitBatchResponse | PermitErrorResponse` — the
16039
+ * effective mode is chosen at runtime, so narrow with `'batchPermitData' in result`.
16040
+ * - `PermitBatchWitnessTransferFrom`: `PermitBatchResponse | PermitErrorResponse`. If batch cannot be
16041
+ * fulfilled (e.g. a v1 contract or batch permits disabled) the result is an error rather than a
16042
+ * silent single-permit downgrade, so `batchPermitData` is guaranteed present on success.
16043
+ * - Any other (single) mode: `PermitSingleResponse | PermitErrorResponse`.
16044
+ * Always check `status === TxnStatus.success` before reading mode-specific fields.
16008
16045
  *
16009
16046
  * @example
16010
16047
  * ```typescript
16011
- * const permitResult = await client.sign({
16048
+ * // Explicit batch request -> result is typed PermitBatchResponse | PermitErrorResponse
16049
+ * const result = await client.sign({
16012
16050
  * chainId: 1,
16013
16051
  * sender: '0x...',
16014
16052
  * tokens: [
@@ -16016,11 +16054,14 @@ var _DZapClient = class _DZapClient {
16016
16054
  * ],
16017
16055
  * service: 'swap',
16018
16056
  * signer: walletClient,
16019
- * permitType: PermitTypes.Permit2,
16020
- * signatureCallback: async ({ permitData, srcToken }) => {
16021
- * console.log(`Signed permit for ${srcToken}:`, permitData);
16022
- * }
16057
+ * permitType: PermitTypes.PermitBatchWitnessTransferFrom,
16023
16058
  * });
16059
+ *
16060
+ * if (result.status === TxnStatus.success) {
16061
+ * console.log('batch permit:', result.batchPermitData);
16062
+ * } else {
16063
+ * console.log('batch permit could not be produced:', result.code);
16064
+ * }
16024
16065
  * ```
16025
16066
  */
16026
16067
  async sign(params) {
package/dist/index.mjs CHANGED
@@ -739,7 +739,9 @@ var DZapPriceProvider = class {
739
739
  this.requiresChainConfig = false;
740
740
  this.fetchPrices = async (chainId, tokenAddresses) => {
741
741
  try {
742
- const tokenPrices = await fetchTokenPrice(tokenAddresses, chainId);
742
+ if (tokenAddresses.length === 0) return {};
743
+ const tokens = tokenAddresses.join(",");
744
+ const tokenPrices = await fetchTokenPrice(tokens, chainId);
743
745
  return tokenPrices;
744
746
  } catch (e) {
745
747
  console.error("Failed to fetch token price", e);
@@ -10697,7 +10699,7 @@ var hyperEvm = /* @__PURE__ */ defineChain({
10697
10699
  }
10698
10700
  });
10699
10701
  var hyperliquid = /* @__PURE__ */ defineChain({
10700
- id: 998,
10702
+ id: 1337,
10701
10703
  name: "Hyperliquid",
10702
10704
  nativeCurrency: { name: "HYPE", symbol: "HYPE", decimals: 18 },
10703
10705
  contracts: {
@@ -12858,7 +12860,7 @@ var exclusiveChainIds = {
12858
12860
  abstract: 2741,
12859
12861
  lens: 232,
12860
12862
  citreaTestnet: 5115,
12861
- hyperLiquid: 998,
12863
+ hyperLiquid: 1337,
12862
12864
  citrea: 4114,
12863
12865
  pushTestnet: 42101,
12864
12866
  astralisTestnet: 71261,
@@ -14252,6 +14254,97 @@ var getPermit2Signature = async (params) => {
14252
14254
 
14253
14255
  // src/transactionHandlers/permit.ts
14254
14256
  var _PermitTxnHandler = class _PermitTxnHandler {
14257
+ static async signPermit(signPermitReq) {
14258
+ const { tokens } = signPermitReq;
14259
+ if (tokens.length === 0) {
14260
+ if (signPermitReq.permitType === PermitTypes.PermitBatchWitnessTransferFrom) {
14261
+ return {
14262
+ status: "success" /* success */,
14263
+ code: 200 /* Success */,
14264
+ batchPermitData: DEFAULT_PERMIT2_DATA,
14265
+ permitType: PermitTypes.PermitBatchWitnessTransferFrom
14266
+ };
14267
+ }
14268
+ return { status: "success" /* success */, code: 200 /* Success */, tokens, permitType: signPermitReq.permitType };
14269
+ }
14270
+ const oneToMany = tokens.length > 1 && isOneToMany(tokens[0].address, tokens[1].address);
14271
+ const shouldUseBatchPermit = _PermitTxnHandler.shouldUseBatchPermit({
14272
+ permitType: signPermitReq.permitType,
14273
+ isBatchPermitAllowed: signPermitReq.isBatchPermitAllowed,
14274
+ tokens,
14275
+ oneToMany,
14276
+ contractVersion: signPermitReq.contractVersion,
14277
+ service: signPermitReq.service
14278
+ });
14279
+ if (shouldUseBatchPermit) {
14280
+ const resp = await _PermitTxnHandler.generateBatchPermitDataForTokens({
14281
+ ...signPermitReq,
14282
+ tokens: tokens.map((token, index) => ({ ...token, index })),
14283
+ account: signPermitReq.sender,
14284
+ permitType: PermitTypes.PermitBatchWitnessTransferFrom
14285
+ //override because only PermitBatchWitnessTransferFrom supports batch
14286
+ });
14287
+ if (resp.status !== "success" /* success */) {
14288
+ return { status: resp.status, code: resp.code, permitType: PermitTypes.PermitBatchWitnessTransferFrom };
14289
+ }
14290
+ if (signPermitReq.signatureCallback) {
14291
+ await signPermitReq.signatureCallback({
14292
+ batchPermitData: resp.permitData,
14293
+ tokens,
14294
+ permitType: resp.permitType
14295
+ });
14296
+ }
14297
+ return {
14298
+ status: "success" /* success */,
14299
+ code: 200 /* Success */,
14300
+ batchPermitData: resp.permitData,
14301
+ permitType: resp.permitType
14302
+ };
14303
+ } else {
14304
+ if (signPermitReq.permitType === PermitTypes.PermitBatchWitnessTransferFrom) {
14305
+ return { status: "error" /* error */, code: 500 /* Error */, permitType: PermitTypes.PermitBatchWitnessTransferFrom };
14306
+ }
14307
+ const totalSrcAmount = calcTotalSrcTokenAmount(tokens);
14308
+ let firstTokenNonce = null;
14309
+ let permitType = _PermitTxnHandler.v1PermitSupport({
14310
+ contractVersion: signPermitReq.contractVersion,
14311
+ service: signPermitReq.service
14312
+ }) ? PermitTypes.PermitSingle : signPermitReq.permitType;
14313
+ for (let dataIdx = 0; dataIdx < tokens.length; dataIdx++) {
14314
+ const isFirstToken = dataIdx === 0;
14315
+ const res = await _PermitTxnHandler.generatePermitDataForToken({
14316
+ ...signPermitReq,
14317
+ token: {
14318
+ ...tokens[dataIdx],
14319
+ index: dataIdx
14320
+ },
14321
+ firstTokenNonce: firstTokenNonce ?? void 0,
14322
+ oneToMany,
14323
+ totalSrcAmount,
14324
+ account: signPermitReq.sender,
14325
+ permitType
14326
+ });
14327
+ permitType = res.permitType;
14328
+ if (res.status !== "success" /* success */) {
14329
+ return { status: res.status, code: res.code, permitType: res.permitType };
14330
+ }
14331
+ tokens[dataIdx].permitData = res.permitData;
14332
+ if (isFirstToken && !isDZapNativeToken(tokens[dataIdx].address)) {
14333
+ firstTokenNonce = res.nonce ?? null;
14334
+ }
14335
+ if (signPermitReq.signatureCallback && !isDZapNativeToken(tokens[dataIdx].address)) {
14336
+ const amount = oneToMany && isFirstToken ? totalSrcAmount : BigInt(tokens[dataIdx].amount);
14337
+ await signPermitReq.signatureCallback({
14338
+ permitData: res.permitData,
14339
+ srcToken: tokens[dataIdx].address,
14340
+ amount: amount.toString(),
14341
+ permitType: res.permitType
14342
+ });
14343
+ }
14344
+ }
14345
+ return { status: "success" /* success */, tokens, code: 200 /* Success */, permitType };
14346
+ }
14347
+ }
14255
14348
  };
14256
14349
  _PermitTxnHandler.generateBatchPermitDataForTokens = async (params) => {
14257
14350
  const resp = await getPermit2Signature(params);
@@ -14388,83 +14481,6 @@ _PermitTxnHandler.shouldUseBatchPermit = ({
14388
14481
  const isContractSupport = !_PermitTxnHandler.v1PermitSupport({ contractVersion, service });
14389
14482
  return isBatchPermitAllowed && (isBatchPermitRequested || shouldAutoBatch) && isContractSupport;
14390
14483
  };
14391
- _PermitTxnHandler.signPermit = async (signPermitReq) => {
14392
- const { tokens } = signPermitReq;
14393
- if (tokens.length === 0) {
14394
- return { status: "success" /* success */, code: 200 /* Success */, tokens, permitType: signPermitReq.permitType };
14395
- }
14396
- const oneToMany = tokens.length > 1 && isOneToMany(tokens[0].address, tokens[1].address);
14397
- const shouldUseBatchPermit = _PermitTxnHandler.shouldUseBatchPermit({
14398
- permitType: signPermitReq.permitType,
14399
- isBatchPermitAllowed: signPermitReq.isBatchPermitAllowed,
14400
- tokens,
14401
- oneToMany,
14402
- contractVersion: signPermitReq.contractVersion,
14403
- service: signPermitReq.service
14404
- });
14405
- if (shouldUseBatchPermit) {
14406
- const resp = await _PermitTxnHandler.generateBatchPermitDataForTokens({
14407
- ...signPermitReq,
14408
- tokens: tokens.map((token, index) => ({ ...token, index })),
14409
- account: signPermitReq.sender,
14410
- permitType: PermitTypes.PermitBatchWitnessTransferFrom
14411
- //override because only PermitBatchWitnessTransferFrom supports batch
14412
- });
14413
- if (resp.status !== "success" /* success */) {
14414
- return { status: resp.status, code: resp.code, permitType: PermitTypes.PermitBatchWitnessTransferFrom };
14415
- }
14416
- if (signPermitReq.signatureCallback) {
14417
- await signPermitReq.signatureCallback({
14418
- batchPermitData: resp.permitData,
14419
- tokens,
14420
- permitType: resp.permitType
14421
- });
14422
- }
14423
- return {
14424
- status: "success" /* success */,
14425
- code: 200 /* Success */,
14426
- batchPermitData: resp.permitData,
14427
- permitType: resp.permitType
14428
- };
14429
- } else {
14430
- const totalSrcAmount = calcTotalSrcTokenAmount(tokens);
14431
- let firstTokenNonce = null;
14432
- let permitType = _PermitTxnHandler.v1PermitSupport({ contractVersion: signPermitReq.contractVersion, service: signPermitReq.service }) ? PermitTypes.PermitSingle : signPermitReq.permitType;
14433
- for (let dataIdx = 0; dataIdx < tokens.length; dataIdx++) {
14434
- const isFirstToken = dataIdx === 0;
14435
- const res = await _PermitTxnHandler.generatePermitDataForToken({
14436
- ...signPermitReq,
14437
- token: {
14438
- ...tokens[dataIdx],
14439
- index: dataIdx
14440
- },
14441
- firstTokenNonce: firstTokenNonce ?? void 0,
14442
- oneToMany,
14443
- totalSrcAmount,
14444
- account: signPermitReq.sender,
14445
- permitType
14446
- });
14447
- permitType = res.permitType;
14448
- if (res.status !== "success" /* success */) {
14449
- return { status: res.status, code: res.code, permitType: res.permitType };
14450
- }
14451
- tokens[dataIdx].permitData = res.permitData;
14452
- if (isFirstToken && !isDZapNativeToken(tokens[dataIdx].address)) {
14453
- firstTokenNonce = res.nonce ?? null;
14454
- }
14455
- if (signPermitReq.signatureCallback && !isDZapNativeToken(tokens[dataIdx].address)) {
14456
- const amount = oneToMany && isFirstToken ? totalSrcAmount : BigInt(tokens[dataIdx].amount);
14457
- await signPermitReq.signatureCallback({
14458
- permitData: res.permitData,
14459
- srcToken: tokens[dataIdx].address,
14460
- amount: amount.toString(),
14461
- permitType: res.permitType
14462
- });
14463
- }
14464
- }
14465
- return { status: "success" /* success */, tokens, code: 200 /* Success */, permitType };
14466
- }
14467
- };
14468
14484
  var PermitTxnHandler = _PermitTxnHandler;
14469
14485
  var permit_default = PermitTxnHandler;
14470
14486
  function encodeApproveCallData({ spender, amount }) {
@@ -14727,6 +14743,61 @@ var signCustomTypedData = async (params) => {
14727
14743
  }
14728
14744
  };
14729
14745
 
14746
+ // src/transactionHandlers/hyperliquid.ts
14747
+ var HyperLiquidTxHandler = class {
14748
+ };
14749
+ HyperLiquidTxHandler.sendTransaction = async (signer, account, txnData, chainId, additionalInfo, updatedQuotes) => {
14750
+ var _a;
14751
+ const signTypedData2 = "signTypedData" in txnData.transaction ? txnData.transaction.signTypedData : null;
14752
+ if (!signTypedData2) {
14753
+ return {
14754
+ status: "error" /* error */,
14755
+ errorMsg: "Missing typed data for HyperLiquid transaction",
14756
+ code: 500 /* Error */
14757
+ };
14758
+ }
14759
+ const txData = [];
14760
+ for (let i = 0; i < signTypedData2.length; i++) {
14761
+ const typedData = signTypedData2[i];
14762
+ const [resp, signatureChainId] = await Promise.all([
14763
+ signCustomTypedData({
14764
+ signer,
14765
+ account,
14766
+ domain: typedData.domain,
14767
+ types: typedData.types,
14768
+ message: typedData.message,
14769
+ primaryType: typedData.primaryType
14770
+ }),
14771
+ signer.getChainId()
14772
+ ]);
14773
+ if (resp.status !== "success" /* success */ || !((_a = resp.data) == null ? void 0 : _a.signature)) {
14774
+ throw new Error("Failed to sign transaction");
14775
+ }
14776
+ txData.push({
14777
+ primaryType: typedData.primaryType,
14778
+ message: typedData.message,
14779
+ signature: resp.data.signature,
14780
+ account,
14781
+ signatureChainId
14782
+ });
14783
+ }
14784
+ const txResp = await broadcastTradeTx({
14785
+ chainId,
14786
+ txData,
14787
+ txId: txnData.txId
14788
+ });
14789
+ if (txResp.status !== "success" /* success */) {
14790
+ throw new Error("Failed to broadcast or save transaction");
14791
+ }
14792
+ return {
14793
+ status: "success" /* success */,
14794
+ code: 200 /* Success */,
14795
+ txnHash: txResp.txnHash,
14796
+ additionalInfo,
14797
+ updatedQuotes
14798
+ };
14799
+ };
14800
+
14730
14801
  // src/transactionHandlers/trade.ts
14731
14802
  var _TradeTxnHandler = class _TradeTxnHandler {
14732
14803
  };
@@ -14800,54 +14871,6 @@ _TradeTxnHandler.sendTxnWithBatch = async (request, signer, txnParams, chainId,
14800
14871
  updatedQuotes
14801
14872
  };
14802
14873
  };
14803
- _TradeTxnHandler.sendHyperLiquidTransaction = async (signer, txnParams, txnData, chainId, additionalInfo, updatedQuotes) => {
14804
- var _a;
14805
- let txnDetails;
14806
- if (chainId === exclusiveChainIds.hyperLiquid) {
14807
- const providerData = additionalInfo ? Object.values(additionalInfo)[0] : null;
14808
- const typedData = providerData && "typedData" in providerData ? providerData.typedData : null;
14809
- if (!additionalInfo || !typedData) {
14810
- return {
14811
- status: "error" /* error */,
14812
- errorMsg: "Missing additional info for HyperLiquid transaction",
14813
- code: 500 /* Error */
14814
- };
14815
- }
14816
- const resp = await signCustomTypedData({
14817
- signer,
14818
- account: txnParams.from,
14819
- domain: typedData.domain,
14820
- types: typedData.types,
14821
- message: typedData.message,
14822
- primaryType: typedData.primaryType
14823
- });
14824
- if (resp.status !== "success" /* success */) {
14825
- throw new Error("Failed to sign transaction");
14826
- }
14827
- txnDetails = (_a = resp.data) == null ? void 0 : _a.signature;
14828
- } else {
14829
- const resp = await _TradeTxnHandler.sendTransaction(signer, txnParams, chainId, additionalInfo, updatedQuotes);
14830
- if (resp.status !== "success" /* success */) {
14831
- throw new Error("Failed to sign transaction");
14832
- }
14833
- txnDetails = resp.txnHash;
14834
- }
14835
- const txResp = await broadcastTradeTx({
14836
- chainId,
14837
- txData: txnDetails,
14838
- txId: txnData.txId
14839
- });
14840
- if (txResp.status !== "success" /* success */) {
14841
- throw new Error("Failed to broadcast or save transaction");
14842
- }
14843
- return {
14844
- status: "success" /* success */,
14845
- code: 200 /* Success */,
14846
- txnHash: txResp.txnHash,
14847
- additionalInfo,
14848
- updatedQuotes
14849
- };
14850
- };
14851
14874
  _TradeTxnHandler.buildAndSendTransaction = async ({
14852
14875
  request,
14853
14876
  signer,
@@ -14867,8 +14890,15 @@ _TradeTxnHandler.buildAndSendTransaction = async ({
14867
14890
  }
14868
14891
  const { data, from, to, value, gasLimit, additionalInfo, updatedQuotes } = buildTxnResponseData;
14869
14892
  const txnParams = { from, to, data, value, gasLimit };
14870
- if ([chainId, ...request.data.map((e) => e.toChain)].some((chain) => chain === exclusiveChainIds.hyperLiquid)) {
14871
- return _TradeTxnHandler.sendHyperLiquidTransaction(signer, txnParams, buildTxnResponseData, chainId, additionalInfo, updatedQuotes);
14893
+ if (chainId === exclusiveChainIds.hyperLiquid) {
14894
+ return HyperLiquidTxHandler.sendTransaction(
14895
+ signer,
14896
+ txnParams.from,
14897
+ buildTxnResponseData,
14898
+ chainId,
14899
+ additionalInfo,
14900
+ updatedQuotes
14901
+ );
14872
14902
  }
14873
14903
  if (batchTransaction && !isTypeSigner(signer)) {
14874
14904
  return _TradeTxnHandler.sendTxnWithBatch(request, signer, txnParams, chainId, additionalInfo, updatedQuotes, multicallAddress, rpcUrls);
@@ -15978,11 +16008,19 @@ var _DZapClient = class _DZapClient {
15978
16008
  * @param params.permitType - Optional permit type (defaults to AutoPermit for optimal compatibility)
15979
16009
  * @param params.signatureCallback - Optional callback function for each completed signature
15980
16010
  * @param params.spender - Optional custom spender address (if not using default DZap contract)
15981
- * @returns Promise resolving to permit signatures and related data
16011
+ * @returns Promise resolving to a {@link SignPermitResponse}, narrowed by the requested `permitType`:
16012
+ * - `AutoPermit` (default): `PermitSingleResponse | PermitBatchResponse | PermitErrorResponse` — the
16013
+ * effective mode is chosen at runtime, so narrow with `'batchPermitData' in result`.
16014
+ * - `PermitBatchWitnessTransferFrom`: `PermitBatchResponse | PermitErrorResponse`. If batch cannot be
16015
+ * fulfilled (e.g. a v1 contract or batch permits disabled) the result is an error rather than a
16016
+ * silent single-permit downgrade, so `batchPermitData` is guaranteed present on success.
16017
+ * - Any other (single) mode: `PermitSingleResponse | PermitErrorResponse`.
16018
+ * Always check `status === TxnStatus.success` before reading mode-specific fields.
15982
16019
  *
15983
16020
  * @example
15984
16021
  * ```typescript
15985
- * const permitResult = await client.sign({
16022
+ * // Explicit batch request -> result is typed PermitBatchResponse | PermitErrorResponse
16023
+ * const result = await client.sign({
15986
16024
  * chainId: 1,
15987
16025
  * sender: '0x...',
15988
16026
  * tokens: [
@@ -15990,11 +16028,14 @@ var _DZapClient = class _DZapClient {
15990
16028
  * ],
15991
16029
  * service: 'swap',
15992
16030
  * signer: walletClient,
15993
- * permitType: PermitTypes.Permit2,
15994
- * signatureCallback: async ({ permitData, srcToken }) => {
15995
- * console.log(`Signed permit for ${srcToken}:`, permitData);
15996
- * }
16031
+ * permitType: PermitTypes.PermitBatchWitnessTransferFrom,
15997
16032
  * });
16033
+ *
16034
+ * if (result.status === TxnStatus.success) {
16035
+ * console.log('batch permit:', result.batchPermitData);
16036
+ * } else {
16037
+ * console.log('batch permit could not be produced:', result.code);
16038
+ * }
15998
16039
  * ```
15999
16040
  */
16000
16041
  async sign(params) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dzapio/sdk",
3
- "version": "2.0.39",
3
+ "version": "2.0.41",
4
4
  "description": "A TypeScript/JavaScript SDK for interacting with the DZap protocol, providing utilities for DeFi operations including Swaps, Bridges, and Zaps.",
5
5
  "main": "dist/index.js",
6
6
  "source": "src/index.ts",