@dzapio/sdk 2.0.4 → 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.
- package/dist/examples/chain-utils.d.ts +1 -0
- package/dist/examples/chain-utils.js +20 -0
- package/dist/examples/permit-utils.d.ts +1 -0
- package/dist/examples/permit-utils.js +90 -0
- package/dist/examples/token-utils.d.ts +1 -0
- package/dist/examples/token-utils.js +41 -0
- package/dist/examples/trade-operations.d.ts +1 -0
- package/dist/examples/trade-operations.js +89 -0
- package/dist/examples/zap-operations.d.ts +1 -0
- package/dist/examples/zap-operations.js +69 -0
- package/dist/src/api/index.d.ts +26 -0
- package/dist/src/api/index.js +140 -0
- package/dist/src/artifacts/ERC20Permit.d.ts +374 -0
- package/dist/src/artifacts/ERC20Permit.js +469 -0
- package/dist/src/artifacts/Permit2.d.ts +700 -0
- package/dist/src/artifacts/Permit2.js +904 -0
- package/dist/src/artifacts/Permit2Proxy.d.ts +416 -0
- package/dist/src/artifacts/Permit2Proxy.js +206 -0
- package/dist/src/artifacts/default/DZapCoreAbi.d.ts +2 -0
- package/dist/src/artifacts/default/DZapCoreAbi.js +3079 -0
- package/dist/src/artifacts/default/DZapCoreV2Abi.d.ts +2 -0
- package/dist/src/artifacts/default/DZapCoreV2Abi.js +3719 -0
- package/dist/src/artifacts/default/DZapDcaAbi.d.ts +2 -0
- package/dist/src/artifacts/default/DZapDcaAbi.js +1829 -0
- package/dist/src/artifacts/default/Permit2Abi.d.ts +700 -0
- package/dist/src/artifacts/default/Permit2Abi.js +904 -0
- package/dist/src/artifacts/default/erc20Abi.d.ts +165 -0
- package/dist/src/artifacts/default/erc20Abi.js +220 -0
- package/dist/src/artifacts/default/index.d.ts +6 -0
- package/dist/src/artifacts/default/index.js +13 -0
- package/dist/src/artifacts/index.d.ts +2 -0
- package/dist/src/artifacts/index.js +9 -0
- package/dist/src/artifacts/staging/DZapCoreSwapAbi.d.ts +2 -0
- package/dist/src/artifacts/staging/DZapCoreSwapAbi.js +3079 -0
- package/dist/src/artifacts/staging/index.d.ts +2 -0
- package/dist/src/artifacts/staging/index.js +5 -0
- package/dist/src/axios/baseClient.d.ts +2 -0
- package/dist/src/axios/baseClient.js +7 -0
- package/dist/src/axios/index.d.ts +8 -0
- package/dist/src/axios/index.js +34 -0
- package/dist/src/chains/definitions/arthera.d.ts +35 -0
- package/dist/src/chains/definitions/arthera.js +28 -0
- package/dist/src/chains/definitions/fiveIre.d.ts +35 -0
- package/dist/src/chains/definitions/fiveIre.js +28 -0
- package/dist/src/chains/definitions/hyperEvm.d.ts +35 -0
- package/dist/src/chains/definitions/hyperEvm.js +26 -0
- package/dist/src/chains/definitions/hyperliquid.d.ts +35 -0
- package/dist/src/chains/definitions/hyperliquid.js +26 -0
- package/dist/src/chains/index.d.ts +143 -0
- package/dist/src/chains/index.js +21 -0
- package/dist/src/config/index.d.ts +36 -0
- package/dist/src/config/index.js +59 -0
- package/dist/src/constants/address.d.ts +12 -0
- package/dist/src/constants/address.js +27 -0
- package/dist/src/constants/approval.d.ts +7 -0
- package/dist/src/constants/approval.js +17 -0
- package/dist/src/constants/axios.d.ts +2 -0
- package/dist/src/constants/axios.js +5 -0
- package/dist/src/constants/chains.d.ts +18 -0
- package/dist/src/constants/chains.js +21 -0
- package/dist/src/constants/contract.d.ts +6 -0
- package/dist/src/constants/contract.js +18 -0
- package/dist/src/constants/erc20.d.ts +25 -0
- package/dist/src/constants/erc20.js +28 -0
- package/dist/src/constants/httpMethods.d.ts +2 -0
- package/dist/src/constants/httpMethods.js +5 -0
- package/dist/src/constants/index.d.ts +48 -0
- package/dist/src/constants/index.js +53 -0
- package/dist/src/constants/permit.d.ts +29 -0
- package/dist/src/constants/permit.js +33 -0
- package/dist/src/constants/permit2.d.ts +2 -0
- package/dist/src/constants/permit2.js +5 -0
- package/dist/src/constants/rpc.d.ts +2 -0
- package/dist/src/constants/rpc.js +5 -0
- package/dist/src/constants/urlConstants.d.ts +15 -0
- package/dist/src/constants/urlConstants.js +18 -0
- package/dist/src/dZapClient/index.d.ts +1013 -0
- package/dist/src/dZapClient/index.js +249 -0
- package/dist/src/enums/index.d.ts +46 -0
- package/dist/src/enums/index.js +57 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.js +50 -0
- package/dist/src/service/cache/cacheProvider.d.ts +10 -0
- package/dist/src/service/cache/cacheProvider.js +72 -0
- package/dist/src/service/cache/constant.d.ts +2 -0
- package/dist/src/service/cache/constant.js +6 -0
- package/dist/src/service/price/index.d.ts +16 -0
- package/dist/src/service/price/index.js +80 -0
- package/dist/src/service/price/provider/coingecko/config.d.ts +6 -0
- package/dist/src/service/price/provider/coingecko/config.js +9 -0
- package/dist/src/service/price/provider/coingecko/index.d.ts +9 -0
- package/dist/src/service/price/provider/coingecko/index.js +66 -0
- package/dist/src/service/price/provider/defiLlama/config.d.ts +3 -0
- package/dist/src/service/price/provider/defiLlama/config.js +6 -0
- package/dist/src/service/price/provider/defiLlama/index.d.ts +9 -0
- package/dist/src/service/price/provider/defiLlama/index.js +60 -0
- package/dist/src/service/price/provider/defiLlama/types.d.ts +11 -0
- package/dist/src/service/price/provider/defiLlama/types.js +2 -0
- package/dist/src/service/price/provider/dzap/index.d.ts +6 -0
- package/dist/src/service/price/provider/dzap/index.js +22 -0
- package/dist/src/service/price/types/IPriceProvider.d.ts +14 -0
- package/dist/src/service/price/types/IPriceProvider.js +8 -0
- package/dist/src/transactionHandlers/generic.d.ts +24 -0
- package/dist/src/transactionHandlers/generic.js +48 -0
- package/dist/src/transactionHandlers/permit.d.ts +61 -0
- package/dist/src/transactionHandlers/permit.js +177 -0
- package/dist/src/transactionHandlers/trade.d.ts +24 -0
- package/dist/src/transactionHandlers/trade.js +263 -0
- package/dist/src/transactionHandlers/zap.d.ts +37 -0
- package/dist/src/transactionHandlers/zap.js +135 -0
- package/dist/src/types/axiosClient.d.ts +6 -0
- package/dist/src/types/axiosClient.js +2 -0
- package/dist/src/types/btc.d.ts +45 -0
- package/dist/src/types/btc.js +2 -0
- package/dist/src/types/chains.d.ts +2 -0
- package/dist/src/types/chains.js +2 -0
- package/dist/src/types/contract.d.ts +14 -0
- package/dist/src/types/contract.js +2 -0
- package/dist/src/types/eip-2612.d.ts +24 -0
- package/dist/src/types/eip-2612.js +58 -0
- package/dist/src/types/index.d.ts +482 -0
- package/dist/src/types/index.js +8 -0
- package/dist/src/types/permit.d.ts +191 -0
- package/dist/src/types/permit.js +54 -0
- package/dist/src/types/wallet.d.ts +2 -0
- package/dist/src/types/wallet.js +2 -0
- package/dist/src/types/zap/build.d.ts +44 -0
- package/dist/src/types/zap/build.js +2 -0
- package/dist/src/types/zap/index.d.ts +34 -0
- package/dist/src/types/zap/index.js +23 -0
- package/dist/src/types/zap/path.d.ts +33 -0
- package/dist/src/types/zap/path.js +2 -0
- package/dist/src/types/zap/pool.d.ts +39 -0
- package/dist/src/types/zap/pool.js +2 -0
- package/dist/src/types/zap/position.d.ts +27 -0
- package/dist/src/types/zap/position.js +2 -0
- package/dist/src/types/zap/quote.d.ts +7 -0
- package/dist/src/types/zap/quote.js +2 -0
- package/dist/src/types/zap/status.d.ts +28 -0
- package/dist/src/types/zap/status.js +2 -0
- package/dist/src/types/zap/step.d.ts +15 -0
- package/dist/src/types/zap/step.js +2 -0
- package/dist/src/utils/amount.d.ts +82 -0
- package/dist/src/utils/amount.js +71 -0
- package/dist/src/utils/axios.d.ts +13 -0
- package/dist/src/utils/axios.js +42 -0
- package/dist/src/utils/date.d.ts +1 -0
- package/dist/src/utils/date.js +8 -0
- package/dist/src/utils/decoder/swap/abis.d.ts +643 -0
- package/dist/src/utils/decoder/swap/abis.js +831 -0
- package/dist/src/utils/decoder/swap/inputDataDecoder.d.ts +14 -0
- package/dist/src/utils/decoder/swap/inputDataDecoder.js +124 -0
- package/dist/src/utils/eip-2612/eip2612Permit.d.ts +23 -0
- package/dist/src/utils/eip-2612/eip2612Permit.js +121 -0
- package/dist/src/utils/eip-5792/batchApproveTokens.d.ts +21 -0
- package/dist/src/utils/eip-5792/batchApproveTokens.js +49 -0
- package/dist/src/utils/eip-5792/index.d.ts +3 -0
- package/dist/src/utils/eip-5792/index.js +9 -0
- package/dist/src/utils/eip-5792/isBatchTxnSupportedByWallet.d.ts +6 -0
- package/dist/src/utils/eip-5792/isBatchTxnSupportedByWallet.js +22 -0
- package/dist/src/utils/eip-5792/sendBatchCalls.d.ts +10 -0
- package/dist/src/utils/eip-5792/sendBatchCalls.js +25 -0
- package/dist/src/utils/eip-5792/waitForBatchTransactionReceipt.d.ts +4 -0
- package/dist/src/utils/eip-5792/waitForBatchTransactionReceipt.js +26 -0
- package/dist/src/utils/encodeApproveCall.d.ts +6 -0
- package/dist/src/utils/encodeApproveCall.js +12 -0
- package/dist/src/utils/erc20.d.ts +65 -0
- package/dist/src/utils/erc20.js +152 -0
- package/dist/src/utils/errors.d.ts +17 -0
- package/dist/src/utils/errors.js +78 -0
- package/dist/src/utils/index.d.ts +4566 -0
- package/dist/src/utils/index.js +196 -0
- package/dist/src/utils/multicall.d.ts +14 -0
- package/dist/src/utils/multicall.js +25 -0
- package/dist/src/utils/permit2/domain.d.ts +2 -0
- package/dist/src/utils/permit2/domain.js +11 -0
- package/dist/src/utils/permit2/index.d.ts +4 -0
- package/dist/src/utils/permit2/index.js +97 -0
- package/dist/src/utils/permit2/nonce.d.ts +15 -0
- package/dist/src/utils/permit2/nonce.js +61 -0
- package/dist/src/utils/permit2/permitData.d.ts +23 -0
- package/dist/src/utils/permit2/permitData.js +85 -0
- package/dist/src/utils/permit2/values.d.ts +54 -0
- package/dist/src/utils/permit2/values.js +88 -0
- package/dist/src/utils/permit2/witnessData.d.ts +4 -0
- package/dist/src/utils/permit2/witnessData.js +48 -0
- package/dist/src/utils/signIntent/custom.d.ts +11 -0
- package/dist/src/utils/signIntent/custom.js +31 -0
- package/dist/src/utils/signIntent/gasless.d.ts +12 -0
- package/dist/src/utils/signIntent/gasless.js +101 -0
- package/dist/src/utils/signTypedData.d.ts +11 -0
- package/dist/src/utils/signTypedData.js +21 -0
- package/dist/src/utils/tokens.d.ts +8 -0
- package/dist/src/utils/tokens.js +73 -0
- package/dist/src/utils/updateQuotes.d.ts +3 -0
- package/dist/src/utils/updateQuotes.js +69 -0
- package/dist/src/zap/constants/index.d.ts +2 -0
- package/dist/src/zap/constants/index.js +18 -0
- package/dist/src/zap/constants/path.d.ts +8 -0
- package/dist/src/zap/constants/path.js +11 -0
- package/dist/src/zap/constants/step.d.ts +3 -0
- package/dist/src/zap/constants/step.js +6 -0
- package/dist/src/zap/constants/urls.d.ts +12 -0
- package/dist/src/zap/constants/urls.js +15 -0
- package/dist/test/build.test.d.ts +1 -0
- package/dist/test/build.test.js +65 -0
- package/dist/test/permit/permit2Nonce.test.d.ts +2 -0
- package/dist/test/permit/permit2Nonce.test.js +96 -0
- package/dist/test/quotes.test.d.ts +1 -0
- package/dist/test/quotes.test.js +59 -0
- package/dist/test/status.test.d.ts +1 -0
- package/dist/test/status.test.js +37 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- 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();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CancelToken } from 'axios';
|
|
2
|
+
import { BroadcastTxParams, CalculatePointsRequest, GaslessExecuteTxParams, TradeBuildTxnRequest, TradeQuotesRequest } from '../types';
|
|
3
|
+
import { ZapBuildTxnRequest, ZapPoolDetailsRequest, ZapPoolsRequest, ZapPositionsRequest, ZapQuoteRequest, ZapStatusRequest } from '../types/zap';
|
|
4
|
+
export declare const fetchTradeQuotes: (request: TradeQuotesRequest) => Promise<any>;
|
|
5
|
+
export declare const fetchTradeBuildTxnData: (request: TradeBuildTxnRequest) => Promise<any>;
|
|
6
|
+
export declare const executeGaslessTxnData: (request: GaslessExecuteTxParams) => Promise<any>;
|
|
7
|
+
export declare const broadcastTx: (request: BroadcastTxParams) => Promise<any>;
|
|
8
|
+
export declare const fetchZapBuildTxnData: (request: ZapBuildTxnRequest, cancelToken?: CancelToken) => Promise<any>;
|
|
9
|
+
export declare const fetchZapQuote: (request: ZapQuoteRequest, cancelToken?: CancelToken) => Promise<any>;
|
|
10
|
+
export declare const fetchZapTxnStatus: (request: ZapStatusRequest) => Promise<any>;
|
|
11
|
+
export declare const fetchZapPositions: (request: ZapPositionsRequest) => Promise<any>;
|
|
12
|
+
export declare const fetchZapPools: (request: ZapPoolsRequest) => Promise<any>;
|
|
13
|
+
export declare const fetchZapPoolDetails: (request: ZapPoolDetailsRequest) => Promise<any>;
|
|
14
|
+
export declare const fetchZapChains: () => Promise<any>;
|
|
15
|
+
export declare const fetchZapProviders: () => Promise<any>;
|
|
16
|
+
export declare const fetchAllSupportedChains: () => Promise<any>;
|
|
17
|
+
export declare const fetchAllTokens: (chainId: number, source?: string, account?: string) => Promise<any>;
|
|
18
|
+
export declare const fetchTokenDetails: (tokenAddress: string | string[], chainId: number, account?: string, includeBalance?: boolean, includePrice?: boolean) => Promise<any>;
|
|
19
|
+
export declare const fetchTokenPrice: (tokenAddresses: string[], chainId: number) => Promise<any>;
|
|
20
|
+
export declare const fetchStatus: ({ txHash, txIds, chainId }: {
|
|
21
|
+
txHash?: string;
|
|
22
|
+
txIds?: string;
|
|
23
|
+
chainId?: number;
|
|
24
|
+
}) => Promise<any>;
|
|
25
|
+
export declare const fetchCalculatedPoints: (request: CalculatePointsRequest) => Promise<any>;
|
|
26
|
+
export declare const fetchBalances: (chainId: number, account: string) => Promise<any>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchBalances = exports.fetchCalculatedPoints = exports.fetchStatus = exports.fetchTokenPrice = exports.fetchTokenDetails = exports.fetchAllTokens = exports.fetchAllSupportedChains = exports.fetchZapProviders = exports.fetchZapChains = exports.fetchZapPoolDetails = exports.fetchZapPools = exports.fetchZapPositions = exports.fetchZapTxnStatus = exports.fetchZapQuote = exports.fetchZapBuildTxnData = exports.broadcastTx = exports.executeGaslessTxnData = exports.fetchTradeBuildTxnData = exports.fetchTradeQuotes = void 0;
|
|
4
|
+
const httpMethods_1 = require("../constants/httpMethods");
|
|
5
|
+
const urlConstants_1 = require("../constants/urlConstants");
|
|
6
|
+
const axios_1 = require("../utils/axios");
|
|
7
|
+
const urls_1 = require("../zap/constants/urls");
|
|
8
|
+
const fetchTradeQuotes = (request) => (0, axios_1.invoke)({
|
|
9
|
+
endpoint: urlConstants_1.QUOTES_URL,
|
|
10
|
+
data: request,
|
|
11
|
+
method: httpMethods_1.POST,
|
|
12
|
+
shouldRetry: true,
|
|
13
|
+
});
|
|
14
|
+
exports.fetchTradeQuotes = fetchTradeQuotes;
|
|
15
|
+
const fetchTradeBuildTxnData = (request) => (0, axios_1.invoke)({
|
|
16
|
+
endpoint: urlConstants_1.BUILD_TX_URL,
|
|
17
|
+
data: request,
|
|
18
|
+
method: httpMethods_1.POST,
|
|
19
|
+
});
|
|
20
|
+
exports.fetchTradeBuildTxnData = fetchTradeBuildTxnData;
|
|
21
|
+
const executeGaslessTxnData = (request) => (0, axios_1.invoke)({
|
|
22
|
+
endpoint: urlConstants_1.GASLESS_EXECUTE_TX_URL,
|
|
23
|
+
data: request,
|
|
24
|
+
method: httpMethods_1.POST,
|
|
25
|
+
});
|
|
26
|
+
exports.executeGaslessTxnData = executeGaslessTxnData;
|
|
27
|
+
const broadcastTx = (request) => (0, axios_1.invoke)({
|
|
28
|
+
endpoint: urlConstants_1.BROADCAST_TX,
|
|
29
|
+
data: request,
|
|
30
|
+
method: httpMethods_1.POST,
|
|
31
|
+
});
|
|
32
|
+
exports.broadcastTx = broadcastTx;
|
|
33
|
+
const fetchZapBuildTxnData = (request, cancelToken) => (0, axios_1.invokeZap)({
|
|
34
|
+
endpoint: urls_1.ZAP_ENDPOINTS.buildTx,
|
|
35
|
+
data: request,
|
|
36
|
+
method: httpMethods_1.POST,
|
|
37
|
+
cancelToken,
|
|
38
|
+
});
|
|
39
|
+
exports.fetchZapBuildTxnData = fetchZapBuildTxnData;
|
|
40
|
+
const fetchZapQuote = (request, cancelToken) => (0, axios_1.invokeZap)({
|
|
41
|
+
endpoint: urls_1.ZAP_ENDPOINTS.quote,
|
|
42
|
+
data: request,
|
|
43
|
+
method: httpMethods_1.POST,
|
|
44
|
+
cancelToken,
|
|
45
|
+
});
|
|
46
|
+
exports.fetchZapQuote = fetchZapQuote;
|
|
47
|
+
const fetchZapTxnStatus = (request) => (0, axios_1.invokeZap)({
|
|
48
|
+
endpoint: urls_1.ZAP_ENDPOINTS.status,
|
|
49
|
+
data: request,
|
|
50
|
+
method: httpMethods_1.GET,
|
|
51
|
+
});
|
|
52
|
+
exports.fetchZapTxnStatus = fetchZapTxnStatus;
|
|
53
|
+
const fetchZapPositions = (request) => (0, axios_1.invokeZap)({
|
|
54
|
+
endpoint: urls_1.ZAP_ENDPOINTS.positions,
|
|
55
|
+
data: request,
|
|
56
|
+
method: httpMethods_1.GET,
|
|
57
|
+
});
|
|
58
|
+
exports.fetchZapPositions = fetchZapPositions;
|
|
59
|
+
const fetchZapPools = (request) => (0, axios_1.invokeZap)({
|
|
60
|
+
endpoint: urls_1.ZAP_ENDPOINTS.pools,
|
|
61
|
+
data: request,
|
|
62
|
+
method: httpMethods_1.GET,
|
|
63
|
+
});
|
|
64
|
+
exports.fetchZapPools = fetchZapPools;
|
|
65
|
+
const fetchZapPoolDetails = (request) => (0, axios_1.invokeZap)({
|
|
66
|
+
endpoint: urls_1.ZAP_ENDPOINTS.poolDetails,
|
|
67
|
+
data: request,
|
|
68
|
+
method: httpMethods_1.GET,
|
|
69
|
+
});
|
|
70
|
+
exports.fetchZapPoolDetails = fetchZapPoolDetails;
|
|
71
|
+
const fetchZapChains = () => (0, axios_1.invokeZap)({
|
|
72
|
+
endpoint: urls_1.ZAP_ENDPOINTS.config.chains,
|
|
73
|
+
method: httpMethods_1.GET,
|
|
74
|
+
});
|
|
75
|
+
exports.fetchZapChains = fetchZapChains;
|
|
76
|
+
const fetchZapProviders = () => (0, axios_1.invokeZap)({
|
|
77
|
+
endpoint: urls_1.ZAP_ENDPOINTS.config.providers,
|
|
78
|
+
method: httpMethods_1.GET,
|
|
79
|
+
});
|
|
80
|
+
exports.fetchZapProviders = fetchZapProviders;
|
|
81
|
+
const fetchAllSupportedChains = () => (0, axios_1.invoke)({
|
|
82
|
+
endpoint: urlConstants_1.GET_ALL_CHAINS_URL,
|
|
83
|
+
data: {},
|
|
84
|
+
method: httpMethods_1.GET,
|
|
85
|
+
shouldRetry: true,
|
|
86
|
+
});
|
|
87
|
+
exports.fetchAllSupportedChains = fetchAllSupportedChains;
|
|
88
|
+
const fetchAllTokens = (chainId, source, account) => (0, axios_1.invoke)({
|
|
89
|
+
endpoint: urlConstants_1.GET_ALL_TOKENS_URL,
|
|
90
|
+
data: { chainId, source, account },
|
|
91
|
+
method: httpMethods_1.GET,
|
|
92
|
+
shouldRetry: true,
|
|
93
|
+
});
|
|
94
|
+
exports.fetchAllTokens = fetchAllTokens;
|
|
95
|
+
const fetchTokenDetails = (tokenAddress, chainId, account, includeBalance, includePrice) => {
|
|
96
|
+
const data = {
|
|
97
|
+
tokenAddress: Array.isArray(tokenAddress) ? undefined : tokenAddress,
|
|
98
|
+
tokenAddresses: Array.isArray(tokenAddress) ? tokenAddress.join(',') : undefined,
|
|
99
|
+
chainId,
|
|
100
|
+
account,
|
|
101
|
+
includeBalance,
|
|
102
|
+
includePrice,
|
|
103
|
+
};
|
|
104
|
+
return (0, axios_1.invoke)({
|
|
105
|
+
endpoint: urlConstants_1.GET_TOKEN_DETAILS_URL,
|
|
106
|
+
data,
|
|
107
|
+
method: httpMethods_1.GET,
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
exports.fetchTokenDetails = fetchTokenDetails;
|
|
111
|
+
const fetchTokenPrice = (tokenAddresses, chainId) => (0, axios_1.invoke)({
|
|
112
|
+
endpoint: urlConstants_1.GET_TOKEN_PRICE,
|
|
113
|
+
data: { tokenAddresses, chainId },
|
|
114
|
+
method: httpMethods_1.GET,
|
|
115
|
+
});
|
|
116
|
+
exports.fetchTokenPrice = fetchTokenPrice;
|
|
117
|
+
const fetchStatus = ({ txHash, txIds, chainId }) => (0, axios_1.invoke)({
|
|
118
|
+
endpoint: urlConstants_1.GET_STATUS,
|
|
119
|
+
data: {
|
|
120
|
+
txHash,
|
|
121
|
+
txIds,
|
|
122
|
+
chainId,
|
|
123
|
+
},
|
|
124
|
+
method: httpMethods_1.GET,
|
|
125
|
+
});
|
|
126
|
+
exports.fetchStatus = fetchStatus;
|
|
127
|
+
const fetchCalculatedPoints = (request) => (0, axios_1.invoke)({
|
|
128
|
+
endpoint: urlConstants_1.CALCULATE_POINTS_URL,
|
|
129
|
+
data: request,
|
|
130
|
+
method: httpMethods_1.POST,
|
|
131
|
+
});
|
|
132
|
+
exports.fetchCalculatedPoints = fetchCalculatedPoints;
|
|
133
|
+
const fetchBalances = (chainId, account) => {
|
|
134
|
+
return (0, axios_1.invoke)({
|
|
135
|
+
endpoint: urlConstants_1.GET_BALANCES,
|
|
136
|
+
data: { chainId, account },
|
|
137
|
+
method: httpMethods_1.GET,
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
exports.fetchBalances = fetchBalances;
|