@dzapio/sdk 2.0.56 → 2.0.57

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
@@ -2161,10 +2161,12 @@ declare const checkEIP2612PermitSupport: ({ address, chainId, rpcUrls, owner, pe
2161
2161
  permit?: TokenPermitData;
2162
2162
  }) => Promise<{
2163
2163
  supportsPermit: boolean;
2164
+ reason?: string;
2164
2165
  data?: {
2165
2166
  version: string;
2166
2167
  name: string;
2167
2168
  nonce: bigint;
2169
+ domain: TypedDataDomain;
2168
2170
  };
2169
2171
  }>;
2170
2172
 
package/dist/index.d.ts CHANGED
@@ -2161,10 +2161,12 @@ declare const checkEIP2612PermitSupport: ({ address, chainId, rpcUrls, owner, pe
2161
2161
  permit?: TokenPermitData;
2162
2162
  }) => Promise<{
2163
2163
  supportsPermit: boolean;
2164
+ reason?: string;
2164
2165
  data?: {
2165
2166
  version: string;
2166
2167
  name: string;
2167
2168
  nonce: bigint;
2169
+ domain: TypedDataDomain;
2168
2170
  };
2169
2171
  }>;
2170
2172
 
package/dist/index.js CHANGED
@@ -11823,6 +11823,30 @@ var multicall = async ({
11823
11823
  };
11824
11824
  }
11825
11825
  };
11826
+ var domainMatchesSeparator = (domain, domainSeparator) => {
11827
+ try {
11828
+ return viem.domainSeparator({ domain }).toLowerCase() === domainSeparator.toLowerCase();
11829
+ } catch {
11830
+ return false;
11831
+ }
11832
+ };
11833
+ var resolveEip2612Domain = ({
11834
+ name,
11835
+ version,
11836
+ chainId,
11837
+ address,
11838
+ domainSeparator
11839
+ }) => {
11840
+ const standard = { name, version, chainId, verifyingContract: address };
11841
+ if (domainMatchesSeparator(standard, domainSeparator)) {
11842
+ return standard;
11843
+ }
11844
+ const salted = { name, version, verifyingContract: address, salt: viem.pad(viem.toHex(chainId), { size: 32 }) };
11845
+ if (domainMatchesSeparator(salted, domainSeparator)) {
11846
+ return salted;
11847
+ }
11848
+ return void 0;
11849
+ };
11826
11850
 
11827
11851
  // src/utils/eip-2612/eip2612Permit.ts
11828
11852
  var eip2612DisabledChains = config.getEip2612DisabledChains();
@@ -11833,7 +11857,7 @@ var checkEIP2612PermitSupport = async ({
11833
11857
  owner,
11834
11858
  permit
11835
11859
  }) => {
11836
- var _a;
11860
+ var _a, _b;
11837
11861
  if (((_a = permit == null ? void 0 : permit.eip2612) == null ? void 0 : _a.supported) === false || eip2612DisabledChains.includes(chainId)) {
11838
11862
  return { supportsPermit: false };
11839
11863
  }
@@ -11885,39 +11909,29 @@ var checkEIP2612PermitSupport = async ({
11885
11909
  if (permitTypeHashResult.status === "success" /* success */ && permitTypeHashResult.result.toLowerCase() !== EIP2612_PERMIT_TYPEHASH.toLowerCase()) {
11886
11910
  return { supportsPermit: false };
11887
11911
  }
11912
+ const onChainSeparator = domainSeparatorResult.result;
11913
+ const supplied = (_b = permit == null ? void 0 : permit.eip2612) == null ? void 0 : _b.domain;
11914
+ const domain = supplied && domainMatchesSeparator(supplied, onChainSeparator) ? supplied : resolveEip2612Domain({ name, version, chainId, address, domainSeparator: onChainSeparator });
11915
+ if (!domain) {
11916
+ const reason = `EIP-712 domain of ${address} on chain ${chainId} matches neither the standard nor the salt layout for name "${name}", version "${version}"`;
11917
+ console.debug(`EIP-2612 permit skipped: ${reason}`);
11918
+ return { supportsPermit: false, reason };
11919
+ }
11888
11920
  return {
11889
11921
  supportsPermit: true,
11890
11922
  data: {
11891
11923
  version,
11892
11924
  name,
11893
- nonce
11925
+ nonce,
11926
+ domain
11894
11927
  }
11895
11928
  };
11896
11929
  };
11897
11930
  var getEIP2612PermitSignature = async (params) => {
11898
- var _a, _b, _c;
11931
+ var _a;
11899
11932
  try {
11900
- const {
11901
- chainId,
11902
- spender,
11903
- account,
11904
- token,
11905
- signer,
11906
- contractVersion,
11907
- service,
11908
- name,
11909
- nonce,
11910
- version,
11911
- deadline = generateDeadline(SignatureExpiryInSecs)
11912
- } = params;
11913
- const { address } = token;
11933
+ const { spender, account, token, signer, contractVersion, service, nonce, domain, deadline = generateDeadline(SignatureExpiryInSecs) } = params;
11914
11934
  const amount = token.amount ? BigInt(token.amount) : viem.maxUint256;
11915
- const domain = ((_b = (_a = token.permit) == null ? void 0 : _a.eip2612) == null ? void 0 : _b.domain) ?? {
11916
- name,
11917
- version,
11918
- chainId,
11919
- verifyingContract: address
11920
- };
11921
11935
  const message = {
11922
11936
  owner: account,
11923
11937
  spender,
@@ -11947,7 +11961,7 @@ var getEIP2612PermitSignature = async (params) => {
11947
11961
  };
11948
11962
  } catch (error) {
11949
11963
  console.log("Error generating permit signature:", error);
11950
- if (((_c = error == null ? void 0 : error.cause) == null ? void 0 : _c.code) === 4001 /* UserRejectedRequest */ || (error == null ? void 0 : error.code) === 4001 /* UserRejectedRequest */) {
11964
+ if (((_a = error == null ? void 0 : error.cause) == null ? void 0 : _a.code) === 4001 /* UserRejectedRequest */ || (error == null ? void 0 : error.code) === 4001 /* UserRejectedRequest */) {
11951
11965
  return { status: "rejected" /* rejected */, code: 4001 /* UserRejectedRequest */ };
11952
11966
  }
11953
11967
  return { status: "error" /* error */, code: 500 /* Error */ };
@@ -13481,17 +13495,15 @@ _PermitTxnHandler.generatePermitDataForToken = async (params) => {
13481
13495
  };
13482
13496
  }
13483
13497
  const amount = oneToMany && isFirstToken ? totalSrcAmount : BigInt(token.amount);
13484
- const eip2612PermitData = await checkEIP2612PermitSupport({
13498
+ const needsEip2612Check = permitType === PermitTypes.AutoPermit || permitType === PermitTypes.EIP2612Permit && !(oneToMany && !isFirstToken);
13499
+ const eip2612PermitData = needsEip2612Check ? await checkEIP2612PermitSupport({
13485
13500
  address: token.address,
13486
13501
  chainId,
13487
13502
  rpcUrls,
13488
13503
  owner: account,
13489
13504
  permit: token.permit
13490
- });
13505
+ }) : { supportsPermit: false };
13491
13506
  if (permitType === PermitTypes.EIP2612Permit || permitType === PermitTypes.AutoPermit && eip2612PermitData.supportsPermit) {
13492
- if (!eip2612PermitData.supportsPermit || !eip2612PermitData.data) {
13493
- throw new Error("Token does not support EIP-2612 permits");
13494
- }
13495
13507
  if (oneToMany && !isFirstToken) {
13496
13508
  return {
13497
13509
  status: "success" /* success */,
@@ -13502,6 +13514,9 @@ _PermitTxnHandler.generatePermitDataForToken = async (params) => {
13502
13514
  permitType: PermitTypes.EIP2612Permit
13503
13515
  };
13504
13516
  }
13517
+ if (!eip2612PermitData.supportsPermit || !eip2612PermitData.data) {
13518
+ throw new Error(`Token does not support EIP-2612 permits${eip2612PermitData.reason ? `: ${eip2612PermitData.reason}` : ""}`);
13519
+ }
13505
13520
  const { permitData, status, code } = await getEIP2612PermitSignature({
13506
13521
  ...params,
13507
13522
  token: {
@@ -13513,7 +13528,8 @@ _PermitTxnHandler.generatePermitDataForToken = async (params) => {
13513
13528
  gasless: false,
13514
13529
  version: eip2612PermitData.data.version,
13515
13530
  name: eip2612PermitData.data.name,
13516
- nonce: eip2612PermitData.data.nonce
13531
+ nonce: eip2612PermitData.data.nonce,
13532
+ domain: eip2612PermitData.data.domain
13517
13533
  });
13518
13534
  return {
13519
13535
  status,
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { encodeAbiParameters, parseAbiParameters, keccak256, encodePacked, stringToHex, defineChain as defineChain$1, zeroAddress as zeroAddress$1, isAddress, getAddress, formatUnits, maxUint256, encodeFunctionData, http, createPublicClient, fallback, decodeAbiParameters, parseEventLogs, maxUint48, getContract } from 'viem';
1
+ import { encodeAbiParameters, parseAbiParameters, keccak256, encodePacked, stringToHex, defineChain as defineChain$1, zeroAddress as zeroAddress$1, isAddress, getAddress, domainSeparator, pad, toHex, formatUnits, maxUint256, encodeFunctionData, http, createPublicClient, fallback, decodeAbiParameters, parseEventLogs, maxUint48, getContract } from 'viem';
2
2
  import Axios from 'axios';
3
3
  import { Signer, utils, ethers } from 'ethers';
4
4
  import * as viemChains from 'viem/chains';
@@ -11798,6 +11798,30 @@ var multicall = async ({
11798
11798
  };
11799
11799
  }
11800
11800
  };
11801
+ var domainMatchesSeparator = (domain, domainSeparator$1) => {
11802
+ try {
11803
+ return domainSeparator({ domain }).toLowerCase() === domainSeparator$1.toLowerCase();
11804
+ } catch {
11805
+ return false;
11806
+ }
11807
+ };
11808
+ var resolveEip2612Domain = ({
11809
+ name,
11810
+ version,
11811
+ chainId,
11812
+ address,
11813
+ domainSeparator
11814
+ }) => {
11815
+ const standard = { name, version, chainId, verifyingContract: address };
11816
+ if (domainMatchesSeparator(standard, domainSeparator)) {
11817
+ return standard;
11818
+ }
11819
+ const salted = { name, version, verifyingContract: address, salt: pad(toHex(chainId), { size: 32 }) };
11820
+ if (domainMatchesSeparator(salted, domainSeparator)) {
11821
+ return salted;
11822
+ }
11823
+ return void 0;
11824
+ };
11801
11825
 
11802
11826
  // src/utils/eip-2612/eip2612Permit.ts
11803
11827
  var eip2612DisabledChains = config.getEip2612DisabledChains();
@@ -11808,7 +11832,7 @@ var checkEIP2612PermitSupport = async ({
11808
11832
  owner,
11809
11833
  permit
11810
11834
  }) => {
11811
- var _a;
11835
+ var _a, _b;
11812
11836
  if (((_a = permit == null ? void 0 : permit.eip2612) == null ? void 0 : _a.supported) === false || eip2612DisabledChains.includes(chainId)) {
11813
11837
  return { supportsPermit: false };
11814
11838
  }
@@ -11860,39 +11884,29 @@ var checkEIP2612PermitSupport = async ({
11860
11884
  if (permitTypeHashResult.status === "success" /* success */ && permitTypeHashResult.result.toLowerCase() !== EIP2612_PERMIT_TYPEHASH.toLowerCase()) {
11861
11885
  return { supportsPermit: false };
11862
11886
  }
11887
+ const onChainSeparator = domainSeparatorResult.result;
11888
+ const supplied = (_b = permit == null ? void 0 : permit.eip2612) == null ? void 0 : _b.domain;
11889
+ const domain = supplied && domainMatchesSeparator(supplied, onChainSeparator) ? supplied : resolveEip2612Domain({ name, version, chainId, address, domainSeparator: onChainSeparator });
11890
+ if (!domain) {
11891
+ const reason = `EIP-712 domain of ${address} on chain ${chainId} matches neither the standard nor the salt layout for name "${name}", version "${version}"`;
11892
+ console.debug(`EIP-2612 permit skipped: ${reason}`);
11893
+ return { supportsPermit: false, reason };
11894
+ }
11863
11895
  return {
11864
11896
  supportsPermit: true,
11865
11897
  data: {
11866
11898
  version,
11867
11899
  name,
11868
- nonce
11900
+ nonce,
11901
+ domain
11869
11902
  }
11870
11903
  };
11871
11904
  };
11872
11905
  var getEIP2612PermitSignature = async (params) => {
11873
- var _a, _b, _c;
11906
+ var _a;
11874
11907
  try {
11875
- const {
11876
- chainId,
11877
- spender,
11878
- account,
11879
- token,
11880
- signer,
11881
- contractVersion,
11882
- service,
11883
- name,
11884
- nonce,
11885
- version,
11886
- deadline = generateDeadline(SignatureExpiryInSecs)
11887
- } = params;
11888
- const { address } = token;
11908
+ const { spender, account, token, signer, contractVersion, service, nonce, domain, deadline = generateDeadline(SignatureExpiryInSecs) } = params;
11889
11909
  const amount = token.amount ? BigInt(token.amount) : maxUint256;
11890
- const domain = ((_b = (_a = token.permit) == null ? void 0 : _a.eip2612) == null ? void 0 : _b.domain) ?? {
11891
- name,
11892
- version,
11893
- chainId,
11894
- verifyingContract: address
11895
- };
11896
11910
  const message = {
11897
11911
  owner: account,
11898
11912
  spender,
@@ -11922,7 +11936,7 @@ var getEIP2612PermitSignature = async (params) => {
11922
11936
  };
11923
11937
  } catch (error) {
11924
11938
  console.log("Error generating permit signature:", error);
11925
- if (((_c = error == null ? void 0 : error.cause) == null ? void 0 : _c.code) === 4001 /* UserRejectedRequest */ || (error == null ? void 0 : error.code) === 4001 /* UserRejectedRequest */) {
11939
+ if (((_a = error == null ? void 0 : error.cause) == null ? void 0 : _a.code) === 4001 /* UserRejectedRequest */ || (error == null ? void 0 : error.code) === 4001 /* UserRejectedRequest */) {
11926
11940
  return { status: "rejected" /* rejected */, code: 4001 /* UserRejectedRequest */ };
11927
11941
  }
11928
11942
  return { status: "error" /* error */, code: 500 /* Error */ };
@@ -13456,17 +13470,15 @@ _PermitTxnHandler.generatePermitDataForToken = async (params) => {
13456
13470
  };
13457
13471
  }
13458
13472
  const amount = oneToMany && isFirstToken ? totalSrcAmount : BigInt(token.amount);
13459
- const eip2612PermitData = await checkEIP2612PermitSupport({
13473
+ const needsEip2612Check = permitType === PermitTypes.AutoPermit || permitType === PermitTypes.EIP2612Permit && !(oneToMany && !isFirstToken);
13474
+ const eip2612PermitData = needsEip2612Check ? await checkEIP2612PermitSupport({
13460
13475
  address: token.address,
13461
13476
  chainId,
13462
13477
  rpcUrls,
13463
13478
  owner: account,
13464
13479
  permit: token.permit
13465
- });
13480
+ }) : { supportsPermit: false };
13466
13481
  if (permitType === PermitTypes.EIP2612Permit || permitType === PermitTypes.AutoPermit && eip2612PermitData.supportsPermit) {
13467
- if (!eip2612PermitData.supportsPermit || !eip2612PermitData.data) {
13468
- throw new Error("Token does not support EIP-2612 permits");
13469
- }
13470
13482
  if (oneToMany && !isFirstToken) {
13471
13483
  return {
13472
13484
  status: "success" /* success */,
@@ -13477,6 +13489,9 @@ _PermitTxnHandler.generatePermitDataForToken = async (params) => {
13477
13489
  permitType: PermitTypes.EIP2612Permit
13478
13490
  };
13479
13491
  }
13492
+ if (!eip2612PermitData.supportsPermit || !eip2612PermitData.data) {
13493
+ throw new Error(`Token does not support EIP-2612 permits${eip2612PermitData.reason ? `: ${eip2612PermitData.reason}` : ""}`);
13494
+ }
13480
13495
  const { permitData, status, code } = await getEIP2612PermitSignature({
13481
13496
  ...params,
13482
13497
  token: {
@@ -13488,7 +13503,8 @@ _PermitTxnHandler.generatePermitDataForToken = async (params) => {
13488
13503
  gasless: false,
13489
13504
  version: eip2612PermitData.data.version,
13490
13505
  name: eip2612PermitData.data.name,
13491
- nonce: eip2612PermitData.data.nonce
13506
+ nonce: eip2612PermitData.data.nonce,
13507
+ domain: eip2612PermitData.data.domain
13492
13508
  });
13493
13509
  return {
13494
13510
  status,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dzapio/sdk",
3
- "version": "2.0.56",
3
+ "version": "2.0.57",
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",