@dzapio/sdk 2.0.3 → 2.0.5

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.
Files changed (222) hide show
  1. package/dist/examples/chain-utils.d.ts +1 -0
  2. package/dist/examples/chain-utils.js +20 -0
  3. package/dist/examples/permit-utils.d.ts +1 -0
  4. package/dist/examples/permit-utils.js +90 -0
  5. package/dist/examples/token-utils.d.ts +1 -0
  6. package/dist/examples/token-utils.js +41 -0
  7. package/dist/examples/trade-operations.d.ts +1 -0
  8. package/dist/examples/trade-operations.js +89 -0
  9. package/dist/examples/zap-operations.d.ts +1 -0
  10. package/dist/examples/zap-operations.js +69 -0
  11. package/dist/index.d.ts +9 -7
  12. package/dist/index.js +1 -1
  13. package/dist/index.m.js +1 -1
  14. package/dist/index.umd.js +1 -1
  15. package/dist/src/api/index.d.ts +26 -0
  16. package/dist/src/api/index.js +140 -0
  17. package/dist/src/artifacts/ERC20Permit.d.ts +374 -0
  18. package/dist/src/artifacts/ERC20Permit.js +469 -0
  19. package/dist/src/artifacts/Permit2.d.ts +700 -0
  20. package/dist/src/artifacts/Permit2.js +904 -0
  21. package/dist/src/artifacts/Permit2Proxy.d.ts +416 -0
  22. package/dist/src/artifacts/Permit2Proxy.js +206 -0
  23. package/dist/src/artifacts/default/DZapCoreAbi.d.ts +2 -0
  24. package/dist/src/artifacts/default/DZapCoreAbi.js +3079 -0
  25. package/dist/src/artifacts/default/DZapCoreV2Abi.d.ts +2 -0
  26. package/dist/src/artifacts/default/DZapCoreV2Abi.js +3719 -0
  27. package/dist/src/artifacts/default/DZapDcaAbi.d.ts +2 -0
  28. package/dist/src/artifacts/default/DZapDcaAbi.js +1829 -0
  29. package/dist/src/artifacts/default/Permit2Abi.d.ts +700 -0
  30. package/dist/src/artifacts/default/Permit2Abi.js +904 -0
  31. package/dist/src/artifacts/default/erc20Abi.d.ts +165 -0
  32. package/dist/src/artifacts/default/erc20Abi.js +220 -0
  33. package/dist/src/artifacts/default/index.d.ts +6 -0
  34. package/dist/src/artifacts/default/index.js +13 -0
  35. package/dist/src/artifacts/index.d.ts +2 -0
  36. package/dist/src/artifacts/index.js +9 -0
  37. package/dist/src/artifacts/staging/DZapCoreSwapAbi.d.ts +2 -0
  38. package/dist/src/artifacts/staging/DZapCoreSwapAbi.js +3079 -0
  39. package/dist/src/artifacts/staging/index.d.ts +2 -0
  40. package/dist/src/artifacts/staging/index.js +5 -0
  41. package/dist/src/axios/baseClient.d.ts +2 -0
  42. package/dist/src/axios/baseClient.js +7 -0
  43. package/dist/src/axios/index.d.ts +8 -0
  44. package/dist/src/axios/index.js +34 -0
  45. package/dist/src/chains/definitions/arthera.d.ts +35 -0
  46. package/dist/src/chains/definitions/arthera.js +28 -0
  47. package/dist/src/chains/definitions/fiveIre.d.ts +35 -0
  48. package/dist/src/chains/definitions/fiveIre.js +28 -0
  49. package/dist/src/chains/definitions/hyperEvm.d.ts +35 -0
  50. package/dist/src/chains/definitions/hyperEvm.js +26 -0
  51. package/dist/src/chains/definitions/hyperliquid.d.ts +35 -0
  52. package/dist/src/chains/definitions/hyperliquid.js +26 -0
  53. package/dist/src/chains/index.d.ts +143 -0
  54. package/dist/src/chains/index.js +21 -0
  55. package/dist/src/config/index.d.ts +36 -0
  56. package/dist/src/config/index.js +59 -0
  57. package/dist/src/constants/address.d.ts +12 -0
  58. package/dist/src/constants/address.js +27 -0
  59. package/dist/src/constants/approval.d.ts +7 -0
  60. package/dist/src/constants/approval.js +17 -0
  61. package/dist/src/constants/axios.d.ts +2 -0
  62. package/dist/src/constants/axios.js +5 -0
  63. package/dist/src/constants/chains.d.ts +18 -0
  64. package/dist/src/constants/chains.js +21 -0
  65. package/dist/src/constants/contract.d.ts +6 -0
  66. package/dist/src/constants/contract.js +18 -0
  67. package/dist/src/constants/erc20.d.ts +25 -0
  68. package/dist/src/constants/erc20.js +28 -0
  69. package/dist/src/constants/httpMethods.d.ts +2 -0
  70. package/dist/src/constants/httpMethods.js +5 -0
  71. package/dist/src/constants/index.d.ts +48 -0
  72. package/dist/src/constants/index.js +53 -0
  73. package/dist/src/constants/permit.d.ts +29 -0
  74. package/dist/src/constants/permit.js +33 -0
  75. package/dist/src/constants/permit2.d.ts +2 -0
  76. package/dist/src/constants/permit2.js +5 -0
  77. package/dist/src/constants/rpc.d.ts +2 -0
  78. package/dist/src/constants/rpc.js +5 -0
  79. package/dist/src/constants/urlConstants.d.ts +15 -0
  80. package/dist/src/constants/urlConstants.js +18 -0
  81. package/dist/src/dZapClient/index.d.ts +1013 -0
  82. package/dist/src/dZapClient/index.js +249 -0
  83. package/dist/src/enums/index.d.ts +46 -0
  84. package/dist/src/enums/index.js +57 -0
  85. package/dist/src/index.d.ts +18 -0
  86. package/dist/src/index.js +50 -0
  87. package/dist/src/service/cache/cacheProvider.d.ts +10 -0
  88. package/dist/src/service/cache/cacheProvider.js +72 -0
  89. package/dist/src/service/cache/constant.d.ts +2 -0
  90. package/dist/src/service/cache/constant.js +6 -0
  91. package/dist/src/service/price/index.d.ts +16 -0
  92. package/dist/src/service/price/index.js +80 -0
  93. package/dist/src/service/price/provider/coingecko/config.d.ts +6 -0
  94. package/dist/src/service/price/provider/coingecko/config.js +9 -0
  95. package/dist/src/service/price/provider/coingecko/index.d.ts +9 -0
  96. package/dist/src/service/price/provider/coingecko/index.js +66 -0
  97. package/dist/src/service/price/provider/defiLlama/config.d.ts +3 -0
  98. package/dist/src/service/price/provider/defiLlama/config.js +6 -0
  99. package/dist/src/service/price/provider/defiLlama/index.d.ts +9 -0
  100. package/dist/src/service/price/provider/defiLlama/index.js +60 -0
  101. package/dist/src/service/price/provider/defiLlama/types.d.ts +11 -0
  102. package/dist/src/service/price/provider/defiLlama/types.js +2 -0
  103. package/dist/src/service/price/provider/dzap/index.d.ts +6 -0
  104. package/dist/src/service/price/provider/dzap/index.js +22 -0
  105. package/dist/src/service/price/types/IPriceProvider.d.ts +14 -0
  106. package/dist/src/service/price/types/IPriceProvider.js +8 -0
  107. package/dist/src/transactionHandlers/generic.d.ts +24 -0
  108. package/dist/src/transactionHandlers/generic.js +48 -0
  109. package/dist/src/transactionHandlers/permit.d.ts +61 -0
  110. package/dist/src/transactionHandlers/permit.js +177 -0
  111. package/dist/src/transactionHandlers/trade.d.ts +24 -0
  112. package/dist/src/transactionHandlers/trade.js +263 -0
  113. package/dist/src/transactionHandlers/zap.d.ts +37 -0
  114. package/dist/src/transactionHandlers/zap.js +135 -0
  115. package/dist/src/types/axiosClient.d.ts +6 -0
  116. package/dist/src/types/axiosClient.js +2 -0
  117. package/dist/src/types/btc.d.ts +45 -0
  118. package/dist/src/types/btc.js +2 -0
  119. package/dist/src/types/chains.d.ts +2 -0
  120. package/dist/src/types/chains.js +2 -0
  121. package/dist/src/types/contract.d.ts +14 -0
  122. package/dist/src/types/contract.js +2 -0
  123. package/dist/src/types/eip-2612.d.ts +24 -0
  124. package/dist/src/types/eip-2612.js +58 -0
  125. package/dist/src/types/index.d.ts +482 -0
  126. package/dist/src/types/index.js +8 -0
  127. package/dist/src/types/permit.d.ts +191 -0
  128. package/dist/src/types/permit.js +54 -0
  129. package/dist/src/types/wallet.d.ts +2 -0
  130. package/dist/src/types/wallet.js +2 -0
  131. package/dist/src/types/zap/build.d.ts +44 -0
  132. package/dist/src/types/zap/build.js +2 -0
  133. package/dist/src/types/zap/index.d.ts +34 -0
  134. package/dist/src/types/zap/index.js +23 -0
  135. package/dist/src/types/zap/path.d.ts +33 -0
  136. package/dist/src/types/zap/path.js +2 -0
  137. package/dist/src/types/zap/pool.d.ts +39 -0
  138. package/dist/src/types/zap/pool.js +2 -0
  139. package/dist/src/types/zap/position.d.ts +27 -0
  140. package/dist/src/types/zap/position.js +2 -0
  141. package/dist/src/types/zap/quote.d.ts +7 -0
  142. package/dist/src/types/zap/quote.js +2 -0
  143. package/dist/src/types/zap/status.d.ts +28 -0
  144. package/dist/src/types/zap/status.js +2 -0
  145. package/dist/src/types/zap/step.d.ts +15 -0
  146. package/dist/src/types/zap/step.js +2 -0
  147. package/dist/src/utils/amount.d.ts +82 -0
  148. package/dist/src/utils/amount.js +71 -0
  149. package/dist/src/utils/axios.d.ts +13 -0
  150. package/dist/src/utils/axios.js +42 -0
  151. package/dist/src/utils/date.d.ts +1 -0
  152. package/dist/src/utils/date.js +8 -0
  153. package/dist/src/utils/decoder/swap/abis.d.ts +643 -0
  154. package/dist/src/utils/decoder/swap/abis.js +831 -0
  155. package/dist/src/utils/decoder/swap/inputDataDecoder.d.ts +14 -0
  156. package/dist/src/utils/decoder/swap/inputDataDecoder.js +124 -0
  157. package/dist/src/utils/eip-2612/eip2612Permit.d.ts +23 -0
  158. package/dist/src/utils/eip-2612/eip2612Permit.js +121 -0
  159. package/dist/src/utils/eip-5792/batchApproveTokens.d.ts +21 -0
  160. package/dist/src/utils/eip-5792/batchApproveTokens.js +49 -0
  161. package/dist/src/utils/eip-5792/index.d.ts +3 -0
  162. package/dist/src/utils/eip-5792/index.js +9 -0
  163. package/dist/src/utils/eip-5792/isBatchTxnSupportedByWallet.d.ts +6 -0
  164. package/dist/src/utils/eip-5792/isBatchTxnSupportedByWallet.js +22 -0
  165. package/dist/src/utils/eip-5792/sendBatchCalls.d.ts +10 -0
  166. package/dist/src/utils/eip-5792/sendBatchCalls.js +25 -0
  167. package/dist/src/utils/eip-5792/waitForBatchTransactionReceipt.d.ts +4 -0
  168. package/dist/src/utils/eip-5792/waitForBatchTransactionReceipt.js +26 -0
  169. package/dist/src/utils/encodeApproveCall.d.ts +6 -0
  170. package/dist/src/utils/encodeApproveCall.js +12 -0
  171. package/dist/src/utils/erc20.d.ts +65 -0
  172. package/dist/src/utils/erc20.js +152 -0
  173. package/dist/src/utils/errors.d.ts +17 -0
  174. package/dist/src/utils/errors.js +78 -0
  175. package/dist/src/utils/index.d.ts +4566 -0
  176. package/dist/src/utils/index.js +196 -0
  177. package/dist/src/utils/multicall.d.ts +14 -0
  178. package/dist/src/utils/multicall.js +25 -0
  179. package/dist/src/utils/permit2/domain.d.ts +2 -0
  180. package/dist/src/utils/permit2/domain.js +11 -0
  181. package/dist/src/utils/permit2/index.d.ts +4 -0
  182. package/dist/src/utils/permit2/index.js +97 -0
  183. package/dist/src/utils/permit2/nonce.d.ts +15 -0
  184. package/dist/src/utils/permit2/nonce.js +61 -0
  185. package/dist/src/utils/permit2/permitData.d.ts +23 -0
  186. package/dist/src/utils/permit2/permitData.js +85 -0
  187. package/dist/src/utils/permit2/values.d.ts +54 -0
  188. package/dist/src/utils/permit2/values.js +88 -0
  189. package/dist/src/utils/permit2/witnessData.d.ts +4 -0
  190. package/dist/src/utils/permit2/witnessData.js +48 -0
  191. package/dist/src/utils/signIntent/custom.d.ts +11 -0
  192. package/dist/src/utils/signIntent/custom.js +31 -0
  193. package/dist/src/utils/signIntent/gasless.d.ts +12 -0
  194. package/dist/src/utils/signIntent/gasless.js +101 -0
  195. package/dist/src/utils/signTypedData.d.ts +11 -0
  196. package/dist/src/utils/signTypedData.js +21 -0
  197. package/dist/src/utils/tokens.d.ts +8 -0
  198. package/dist/src/utils/tokens.js +73 -0
  199. package/dist/src/utils/updateQuotes.d.ts +3 -0
  200. package/dist/src/utils/updateQuotes.js +69 -0
  201. package/dist/src/zap/constants/index.d.ts +2 -0
  202. package/dist/src/zap/constants/index.js +18 -0
  203. package/dist/src/zap/constants/path.d.ts +8 -0
  204. package/dist/src/zap/constants/path.js +11 -0
  205. package/dist/src/zap/constants/step.d.ts +3 -0
  206. package/dist/src/zap/constants/step.js +6 -0
  207. package/dist/src/zap/constants/urls.d.ts +12 -0
  208. package/dist/src/zap/constants/urls.js +15 -0
  209. package/dist/test/build.test.d.ts +1 -0
  210. package/dist/test/build.test.js +65 -0
  211. package/dist/test/permit/permit2Nonce.test.d.ts +2 -0
  212. package/dist/test/permit/permit2Nonce.test.js +96 -0
  213. package/dist/test/quotes.test.d.ts +1 -0
  214. package/dist/test/quotes.test.js +59 -0
  215. package/dist/test/status.test.d.ts +1 -0
  216. package/dist/test/status.test.js +37 -0
  217. package/dist/tsconfig.tsbuildinfo +1 -0
  218. package/dist/utils/decoder/swap/abis.d.ts +643 -0
  219. package/dist/utils/decoder/swap/inputDataDecoder.d.ts +14 -0
  220. package/dist/utils/index.d.ts +2 -4
  221. package/dist/utils/tokens.d.ts +3 -2
  222. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const src_1 = require("../src");
4
+ const dZapClient = src_1.DZapClient.getInstance();
5
+ async function runChainUtilsExamples() {
6
+ console.log('Running Chain Utilities examples...');
7
+ console.log('\nFetching all supported chains...');
8
+ try {
9
+ const allChains = await dZapClient.getAllSupportedChains();
10
+ console.log(`Found ${Object.keys(allChains).length} supported chains.`);
11
+ const chainSubset = Object.fromEntries(Object.entries(allChains)
12
+ .slice(0, 3)
13
+ .map(([key, value]) => [key, { name: value.name, chainId: value.chainId, coin: value.coin }]));
14
+ console.log('Chain subset:', JSON.stringify(chainSubset, null, 2));
15
+ }
16
+ catch (error) {
17
+ console.error('Error fetching all chains:', error);
18
+ }
19
+ }
20
+ runChainUtilsExamples();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const viem_1 = require("viem");
4
+ const chains_1 = require("viem/chains");
5
+ const src_1 = require("../src");
6
+ const dZapClient = src_1.DZapClient.getInstance();
7
+ const walletClient = (0, viem_1.createWalletClient)({
8
+ transport: (0, viem_1.http)(),
9
+ account: '0xYourWalletAddress',
10
+ chain: chains_1.arbitrum,
11
+ });
12
+ async function runPermitExamples() {
13
+ console.log('Running Permit examples...');
14
+ const chainId = 42161;
15
+ const senderAddress = '0xYourWalletAddress';
16
+ const tokenToApprove = '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1';
17
+ const amountToTrade = (0, viem_1.parseUnits)('1000', 18).toString();
18
+ const rpcUrls = ['https://arb1.arbitrum.io/rpc'];
19
+ console.log('\nChecking allowance...');
20
+ try {
21
+ const allowanceResponse = await dZapClient.getAllowance({
22
+ chainId,
23
+ sender: senderAddress,
24
+ service: src_1.Services.trade,
25
+ tokens: [{ address: tokenToApprove, amount: amountToTrade }],
26
+ rpcUrls,
27
+ mode: src_1.ApprovalModes.PermitWitnessTransferFrom,
28
+ });
29
+ console.log('Allowance details:', JSON.stringify(allowanceResponse, null, 2));
30
+ const { approvalNeeded } = allowanceResponse.data[tokenToApprove];
31
+ if (walletClient.account && approvalNeeded) {
32
+ console.log('\nAllowance is insufficient. Requesting approval...');
33
+ try {
34
+ await dZapClient.approve({
35
+ chainId,
36
+ signer: walletClient,
37
+ service: src_1.Services.trade,
38
+ mode: src_1.ApprovalModes.PermitWitnessTransferFrom,
39
+ tokens: [{ address: tokenToApprove, amount: amountToTrade }],
40
+ approvalTxnCallback: async ({ txnDetails, address, }) => {
41
+ console.log(`Approval transaction sent for ${address}:`, txnDetails);
42
+ return null;
43
+ },
44
+ });
45
+ console.log('Approval transaction sent. Please confirm in your wallet.');
46
+ }
47
+ catch (error) {
48
+ console.error('Error during approval:', error);
49
+ }
50
+ }
51
+ else if (!walletClient.account) {
52
+ console.log('\nSkipping approval check as no wallet client is available.');
53
+ }
54
+ else {
55
+ console.log('\nSufficient allowance already granted.');
56
+ }
57
+ }
58
+ catch (error) {
59
+ console.error('An error occurred checking allowance:', error);
60
+ }
61
+ console.log('\nSigning permit...');
62
+ if (walletClient.account) {
63
+ try {
64
+ const signResponse = await dZapClient.sign({
65
+ chainId,
66
+ signer: walletClient,
67
+ sender: senderAddress,
68
+ service: src_1.Services.trade,
69
+ permitType: src_1.PermitTypes.PermitWitnessTransferFrom,
70
+ tokens: [
71
+ {
72
+ address: tokenToApprove,
73
+ amount: amountToTrade.toString(),
74
+ },
75
+ ],
76
+ signatureCallback: async (params) => {
77
+ console.log(`Signature received for`, params);
78
+ },
79
+ });
80
+ console.log('Sign response:', signResponse);
81
+ }
82
+ catch (error) {
83
+ console.error('Error signing permit:', error);
84
+ }
85
+ }
86
+ else {
87
+ console.log('Skipping sign permit as no wallet client is available.');
88
+ }
89
+ }
90
+ runPermitExamples();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const src_1 = require("../src");
4
+ const dZapClient = src_1.DZapClient.getInstance();
5
+ async function runTokenUtilsExamples() {
6
+ console.log('Running Token Utilities examples...');
7
+ const arbitrumChainId = 42161;
8
+ console.log(`\nFetching all tokens for chain ${arbitrumChainId}...`);
9
+ try {
10
+ const allTokens = await dZapClient.getAllTokens(arbitrumChainId);
11
+ console.log(`Found ${Object.keys(allTokens).length} tokens.`);
12
+ console.log('First 5 tokens:', Object.fromEntries(Object.entries(allTokens).slice(0, 5)));
13
+ }
14
+ catch (error) {
15
+ console.error('Error fetching all tokens:', error);
16
+ }
17
+ const usdcAddress = '0xaf88d065e77c8cC2239327C5EDb3A432268e5831';
18
+ const userAddress = '0xYourWalletAddress';
19
+ console.log(`\nFetching details for USDC on arbitrum...`);
20
+ try {
21
+ const tokenDetails = await dZapClient.getTokenDetails(usdcAddress, arbitrumChainId, userAddress, true, true);
22
+ console.log('Token details:', JSON.stringify(tokenDetails, null, 2));
23
+ }
24
+ catch (error) {
25
+ console.error('Error fetching token details:', error);
26
+ }
27
+ const tokensToPrice = [
28
+ '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
29
+ '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
30
+ '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',
31
+ ];
32
+ console.log(`\nFetching prices for ${tokensToPrice.length} tokens...`);
33
+ try {
34
+ const tokenPrices = await dZapClient.getTokenPrices(tokensToPrice, arbitrumChainId);
35
+ console.log('Token prices:', JSON.stringify(tokenPrices, null, 2));
36
+ }
37
+ catch (error) {
38
+ console.error('Error fetching token prices:', error);
39
+ }
40
+ }
41
+ runTokenUtilsExamples();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const viem_1 = require("viem");
4
+ const chains_1 = require("viem/chains");
5
+ const src_1 = require("../src");
6
+ const dZapClient = src_1.DZapClient.getInstance();
7
+ const walletClient = (0, viem_1.createWalletClient)({
8
+ transport: (0, viem_1.http)(),
9
+ account: '0xYourWalletAddress',
10
+ chain: chains_1.arbitrum,
11
+ });
12
+ async function runTradeExamples() {
13
+ console.log('Running Swap and Bridge examples...');
14
+ console.log('\nFetching quotes...');
15
+ const userAddress = walletClient.account.address;
16
+ const quotesRequest = {
17
+ fromChain: 42161,
18
+ data: [
19
+ {
20
+ amount: '374980',
21
+ srcToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
22
+ destToken: '0x4200000000000000000000000000000000000006',
23
+ toChain: 8453,
24
+ slippage: 1,
25
+ },
26
+ ],
27
+ account: userAddress,
28
+ };
29
+ try {
30
+ const quotesResponse = await dZapClient.getTradeQuotes(quotesRequest);
31
+ console.log('Quotes received:', JSON.stringify(quotesResponse, null, 2));
32
+ const pairKey = Object.keys(quotesResponse)[0];
33
+ const pairQuoteData = quotesResponse[pairKey];
34
+ if (!pairQuoteData.quoteRates || Object.keys(pairQuoteData.quoteRates).length === 0) {
35
+ console.log('No routes found for the requested trade.');
36
+ return;
37
+ }
38
+ const bestRouteKey = pairQuoteData.recommendedSource;
39
+ const bestQuote = pairQuoteData.quoteRates[bestRouteKey];
40
+ console.log(`\nBest route found via ${bestRouteKey}`);
41
+ console.log('\nApproval is likely required for non-native tokens.');
42
+ console.log('\nBuilding and sending transaction...');
43
+ const buildTxRequest = {
44
+ fromChain: 42161,
45
+ sender: userAddress,
46
+ refundee: userAddress,
47
+ gasless: false,
48
+ data: [
49
+ {
50
+ amount: bestQuote.srcAmount,
51
+ srcToken: bestQuote.srcToken.address,
52
+ destToken: bestQuote.destToken.address,
53
+ toChain: 8453,
54
+ protocol: bestRouteKey,
55
+ recipient: userAddress,
56
+ slippage: 1,
57
+ },
58
+ ],
59
+ };
60
+ const txResult = await dZapClient.trade({
61
+ request: buildTxRequest,
62
+ signer: walletClient,
63
+ });
64
+ console.log('Transaction response:', txResult);
65
+ if (txResult.status === 'success' && txResult.txnHash) {
66
+ console.log(`Transaction sent successfully! Hash: ${txResult.txnHash}`);
67
+ console.log('\nFetching transaction status in 15 seconds...');
68
+ setTimeout(async () => {
69
+ try {
70
+ const statusResponse = (await dZapClient.getTradeTxnStatus({
71
+ txHash: txResult.txnHash,
72
+ chainId: 42161,
73
+ }));
74
+ console.log('Transaction status:', JSON.stringify(statusResponse, null, 2));
75
+ }
76
+ catch (e) {
77
+ console.error('Error getting status:', e);
78
+ }
79
+ }, 15000);
80
+ }
81
+ else {
82
+ console.error('Transaction failed or hash not found:', txResult.errorMsg);
83
+ }
84
+ }
85
+ catch (error) {
86
+ console.error('An error occurred during swap/bridge operations:', error);
87
+ }
88
+ }
89
+ runTradeExamples();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const viem_1 = require("viem");
4
+ const chains_1 = require("viem/chains");
5
+ const src_1 = require("../src");
6
+ const dZapClient = src_1.DZapClient.getInstance();
7
+ const walletClient = (0, viem_1.createWalletClient)({
8
+ transport: (0, viem_1.http)(),
9
+ account: '0xYourWalletAddress',
10
+ chain: chains_1.arbitrum,
11
+ });
12
+ async function runZapExamples() {
13
+ console.log('Running Zap examples...');
14
+ const userAddress = '0xYourWalletAddress';
15
+ console.log('\nFetching zap quote...');
16
+ const zapQuoteRequest = {
17
+ srcChainId: 42161,
18
+ destChainId: 42161,
19
+ account: userAddress,
20
+ srcToken: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
21
+ destToken: '0x724dc807b04555b71ed48a6896b6F41593b8C637',
22
+ amount: '374980',
23
+ recipient: userAddress,
24
+ refundee: userAddress,
25
+ slippage: 1,
26
+ };
27
+ try {
28
+ const zapQuoteResponse = await dZapClient.getZapQuote(zapQuoteRequest);
29
+ console.log('Zap quote received:', JSON.stringify(zapQuoteResponse, null, 2));
30
+ if (!zapQuoteResponse) {
31
+ console.log('Could not generate a zap transaction plan.');
32
+ return;
33
+ }
34
+ console.log('\nApproval is likely required for non-native tokens.');
35
+ console.log('\nExecuting zap...');
36
+ if (walletClient.account) {
37
+ try {
38
+ const zapResult = await dZapClient.zap({
39
+ request: zapQuoteRequest,
40
+ signer: walletClient,
41
+ });
42
+ console.log('Zap execution result:', zapResult);
43
+ if (zapResult.status !== src_1.TxnStatus.success || !zapResult.txnHash) {
44
+ throw new Error('Zap execution failed');
45
+ }
46
+ const txnHash = zapResult.txnHash;
47
+ setTimeout(async () => {
48
+ try {
49
+ const statusResponse = await dZapClient.getZapTxnStatus({ chainId: 42161, txnHash });
50
+ console.log('Zap transaction status:', JSON.stringify(statusResponse, null, 2));
51
+ }
52
+ catch (e) {
53
+ console.error('Error getting zap status:', e);
54
+ }
55
+ }, 15000);
56
+ }
57
+ catch (error) {
58
+ console.error('Error during zap execution:', error);
59
+ }
60
+ }
61
+ else {
62
+ console.log('Skipping zap execution as no wallet client is available.');
63
+ }
64
+ }
65
+ catch (error) {
66
+ console.error('An error occurred during zap operations:', error);
67
+ }
68
+ }
69
+ runZapExamples();
package/dist/index.d.ts CHANGED
@@ -1,16 +1,18 @@
1
+ import { broadcastTx } from './api';
1
2
  import { OtherAbis, QuoteFilters, Services, STATUS } from './constants';
2
- import { SignatureExpiryInSecs } from './constants/permit2';
3
- import { DZapPermitMode, StatusCodes, TxnStatus } from './enums';
4
- import { ApiRpcResponse, ApprovalMode, BatchPermitCallbackParams, Chain, ChainData, contractErrorActions, ContractErrorResponse, DZapTransactionResponse, Fee, FeeDetails, GaslessTradeBuildTxnResponse, HexString, PermitMode, ProviderDetails, QuoteFilter, SignatureCallbackParams, SinglePermitCallbackParams, SwapInfo, Token, TokenInfo, TokenResponse, TradeBuildTxnRequest, TradeBuildTxnRequestData, TradeBuildTxnResponse, TradePath, TradeQuotesRequest, TradeQuotesRequestData, TradeQuotesResponse, TradeStatusResponse, TradeStep, EvmTxData, SvmTxData, BtcTxData, TradeGasBuildTxnResponse, ParamQuotes, SignPermitResponse, TokenPermitData } from './types';
5
- import { PsbtInput, PsbtOutput } from './types/btc';
6
- import { formatToken, getTokensPairKey } from './utils';
7
3
  import { ApprovalModes } from './constants/approval';
8
4
  import { erc20Functions } from './constants/erc20';
9
5
  import { PermitTypes } from './constants/permit';
6
+ import { SignatureExpiryInSecs } from './constants/permit2';
10
7
  import DZapClient from './dZapClient';
8
+ import { DZapPermitMode, StatusCodes, TxnStatus } from './enums';
9
+ import { ApiRpcResponse, ApprovalMode, BatchPermitCallbackParams, BtcTxData, Chain, ChainData, contractErrorActions, ContractErrorResponse, DZapTransactionResponse, EvmTxData, Fee, FeeDetails, GaslessTradeBuildTxnResponse, HexString, ParamQuotes, PermitMode, ProviderDetails, QuoteFilter, SignatureCallbackParams, SignPermitResponse, SinglePermitCallbackParams, SvmTxData, SwapInfo, Token, TokenInfo, TokenPermitData, TokenResponse, TradeBuildTxnRequest, TradeBuildTxnRequestData, TradeBuildTxnResponse, TradeGasBuildTxnResponse, TradePath, TradeQuotesRequest, TradeQuotesRequestData, TradeQuotesResponse, TradeStatusResponse, TradeStep } from './types';
10
+ import { PsbtInput, PsbtOutput } from './types/btc';
11
11
  import { ZapIntegratorConfig, ZapStatusResponse } from './types/zap';
12
+ import { getTokensPairKey } from './utils';
13
+ import { SwapInputDataDecoder } from './utils/decoder/swap/inputDataDecoder';
12
14
  import { checkEIP2612PermitSupport } from './utils/eip-2612/eip2612Permit';
13
- import { broadcastTx } from './api';
15
+ import { formatToken } from './utils/tokens';
14
16
  export * from './types/zap';
15
17
  export * from './zap/constants';
16
- export { ApiRpcResponse, ApprovalMode, ApprovalModes, BatchPermitCallbackParams, Chain, ChainData, checkEIP2612PermitSupport, contractErrorActions, ContractErrorResponse, DZapClient, DZapPermitMode, DZapTransactionResponse, erc20Functions, Fee, FeeDetails, formatToken, GaslessTradeBuildTxnResponse, getTokensPairKey, HexString, OtherAbis, PermitMode, PermitTypes, ProviderDetails, PsbtInput, PsbtOutput, QuoteFilter, QuoteFilters, Services, SignatureCallbackParams, SignatureExpiryInSecs, SinglePermitCallbackParams, STATUS, StatusCodes, SwapInfo, Token, TokenInfo, TokenResponse, TradeBuildTxnRequest, TradeBuildTxnRequestData, TradeBuildTxnResponse, TradePath, TradeQuotesRequest, TradeQuotesRequestData, TradeQuotesResponse, TradeStatusResponse, TradeStep, TxnStatus, ZapStatusResponse, ZapIntegratorConfig, EvmTxData, SvmTxData, BtcTxData, TradeGasBuildTxnResponse, ParamQuotes, SignPermitResponse, TokenPermitData, broadcastTx, };
18
+ export { ApiRpcResponse, ApprovalMode, ApprovalModes, BatchPermitCallbackParams, broadcastTx, BtcTxData, Chain, ChainData, checkEIP2612PermitSupport, contractErrorActions, ContractErrorResponse, DZapClient, DZapPermitMode, DZapTransactionResponse, erc20Functions, EvmTxData, Fee, FeeDetails, formatToken, GaslessTradeBuildTxnResponse, getTokensPairKey, HexString, OtherAbis, ParamQuotes, PermitMode, PermitTypes, ProviderDetails, PsbtInput, PsbtOutput, QuoteFilter, QuoteFilters, Services, SignatureCallbackParams, SignatureExpiryInSecs, SignPermitResponse, SinglePermitCallbackParams, STATUS, StatusCodes, SvmTxData, SwapInfo, SwapInputDataDecoder, Token, TokenInfo, TokenPermitData, TokenResponse, TradeBuildTxnRequest, TradeBuildTxnRequestData, TradeBuildTxnResponse, TradeGasBuildTxnResponse, TradePath, TradeQuotesRequest, TradeQuotesRequestData, TradeQuotesResponse, TradeStatusResponse, TradeStep, TxnStatus, ZapIntegratorConfig, ZapStatusResponse, };