@dzapio/sdk 2.0.7 → 2.0.8
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/api/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/index.m.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/zap/broadcast.d.ts +15 -0
- package/package.json +1 -1
- package/dist/examples/chain-utils.d.ts +0 -1
- package/dist/examples/chain-utils.js +0 -20
- package/dist/examples/permit-utils.d.ts +0 -1
- package/dist/examples/permit-utils.js +0 -90
- package/dist/examples/token-utils.d.ts +0 -1
- package/dist/examples/token-utils.js +0 -41
- package/dist/examples/trade-operations.d.ts +0 -1
- package/dist/examples/trade-operations.js +0 -89
- package/dist/examples/zap-operations.d.ts +0 -1
- package/dist/examples/zap-operations.js +0 -69
- package/dist/src/api/index.d.ts +0 -27
- package/dist/src/api/index.js +0 -146
- package/dist/src/artifacts/ERC20Permit.d.ts +0 -374
- package/dist/src/artifacts/ERC20Permit.js +0 -469
- package/dist/src/artifacts/Permit2.d.ts +0 -700
- package/dist/src/artifacts/Permit2.js +0 -904
- package/dist/src/artifacts/Permit2Proxy.d.ts +0 -416
- package/dist/src/artifacts/Permit2Proxy.js +0 -206
- package/dist/src/artifacts/default/DZapCoreAbi.d.ts +0 -2
- package/dist/src/artifacts/default/DZapCoreAbi.js +0 -3079
- package/dist/src/artifacts/default/DZapCoreV2Abi.d.ts +0 -2
- package/dist/src/artifacts/default/DZapCoreV2Abi.js +0 -3719
- package/dist/src/artifacts/default/DZapDcaAbi.d.ts +0 -2
- package/dist/src/artifacts/default/DZapDcaAbi.js +0 -1829
- package/dist/src/artifacts/default/Permit2Abi.d.ts +0 -700
- package/dist/src/artifacts/default/Permit2Abi.js +0 -904
- package/dist/src/artifacts/default/erc20Abi.d.ts +0 -165
- package/dist/src/artifacts/default/erc20Abi.js +0 -220
- package/dist/src/artifacts/default/index.d.ts +0 -6
- package/dist/src/artifacts/default/index.js +0 -13
- package/dist/src/artifacts/index.d.ts +0 -2
- package/dist/src/artifacts/index.js +0 -9
- package/dist/src/artifacts/staging/DZapCoreSwapAbi.d.ts +0 -2
- package/dist/src/artifacts/staging/DZapCoreSwapAbi.js +0 -3079
- package/dist/src/artifacts/staging/index.d.ts +0 -2
- package/dist/src/artifacts/staging/index.js +0 -5
- package/dist/src/axios/baseClient.d.ts +0 -2
- package/dist/src/axios/baseClient.js +0 -7
- package/dist/src/axios/index.d.ts +0 -8
- package/dist/src/axios/index.js +0 -34
- package/dist/src/chains/definitions/arthera.d.ts +0 -35
- package/dist/src/chains/definitions/arthera.js +0 -28
- package/dist/src/chains/definitions/fiveIre.d.ts +0 -35
- package/dist/src/chains/definitions/fiveIre.js +0 -28
- package/dist/src/chains/definitions/hyperEvm.d.ts +0 -35
- package/dist/src/chains/definitions/hyperEvm.js +0 -26
- package/dist/src/chains/definitions/hyperliquid.d.ts +0 -35
- package/dist/src/chains/definitions/hyperliquid.js +0 -26
- package/dist/src/chains/definitions/stable.d.ts +0 -36
- package/dist/src/chains/definitions/stable.js +0 -31
- package/dist/src/chains/index.d.ts +0 -179
- package/dist/src/chains/index.js +0 -24
- package/dist/src/config/index.d.ts +0 -36
- package/dist/src/config/index.js +0 -59
- package/dist/src/constants/address.d.ts +0 -13
- package/dist/src/constants/address.js +0 -29
- package/dist/src/constants/approval.d.ts +0 -7
- package/dist/src/constants/approval.js +0 -17
- package/dist/src/constants/axios.d.ts +0 -2
- package/dist/src/constants/axios.js +0 -5
- package/dist/src/constants/chains.d.ts +0 -31
- package/dist/src/constants/chains.js +0 -34
- package/dist/src/constants/contract.d.ts +0 -6
- package/dist/src/constants/contract.js +0 -18
- package/dist/src/constants/erc20.d.ts +0 -25
- package/dist/src/constants/erc20.js +0 -28
- package/dist/src/constants/httpMethods.d.ts +0 -2
- package/dist/src/constants/httpMethods.js +0 -5
- package/dist/src/constants/index.d.ts +0 -48
- package/dist/src/constants/index.js +0 -53
- package/dist/src/constants/permit.d.ts +0 -29
- package/dist/src/constants/permit.js +0 -33
- package/dist/src/constants/permit2.d.ts +0 -2
- package/dist/src/constants/permit2.js +0 -5
- package/dist/src/constants/rpc.d.ts +0 -2
- package/dist/src/constants/rpc.js +0 -5
- package/dist/src/constants/urlConstants.d.ts +0 -15
- package/dist/src/constants/urlConstants.js +0 -18
- package/dist/src/dZapClient/index.d.ts +0 -1015
- package/dist/src/dZapClient/index.js +0 -255
- package/dist/src/enums/index.d.ts +0 -46
- package/dist/src/enums/index.js +0 -57
- package/dist/src/index.d.ts +0 -17
- package/dist/src/index.js +0 -48
- package/dist/src/service/cache/cacheProvider.d.ts +0 -10
- package/dist/src/service/cache/cacheProvider.js +0 -72
- package/dist/src/service/cache/constant.d.ts +0 -2
- package/dist/src/service/cache/constant.js +0 -6
- package/dist/src/service/price/index.d.ts +0 -16
- package/dist/src/service/price/index.js +0 -80
- package/dist/src/service/price/provider/coingecko/config.d.ts +0 -6
- package/dist/src/service/price/provider/coingecko/config.js +0 -9
- package/dist/src/service/price/provider/coingecko/index.d.ts +0 -9
- package/dist/src/service/price/provider/coingecko/index.js +0 -66
- package/dist/src/service/price/provider/defiLlama/config.d.ts +0 -3
- package/dist/src/service/price/provider/defiLlama/config.js +0 -6
- package/dist/src/service/price/provider/defiLlama/index.d.ts +0 -9
- package/dist/src/service/price/provider/defiLlama/index.js +0 -60
- package/dist/src/service/price/provider/defiLlama/types.d.ts +0 -11
- package/dist/src/service/price/provider/defiLlama/types.js +0 -2
- package/dist/src/service/price/provider/dzap/index.d.ts +0 -6
- package/dist/src/service/price/provider/dzap/index.js +0 -22
- package/dist/src/service/price/types/IPriceProvider.d.ts +0 -14
- package/dist/src/service/price/types/IPriceProvider.js +0 -8
- package/dist/src/transactionHandlers/generic.d.ts +0 -24
- package/dist/src/transactionHandlers/generic.js +0 -48
- package/dist/src/transactionHandlers/permit.d.ts +0 -61
- package/dist/src/transactionHandlers/permit.js +0 -177
- package/dist/src/transactionHandlers/trade.d.ts +0 -24
- package/dist/src/transactionHandlers/trade.js +0 -263
- package/dist/src/transactionHandlers/zap.d.ts +0 -37
- package/dist/src/transactionHandlers/zap.js +0 -135
- package/dist/src/types/axiosClient.d.ts +0 -6
- package/dist/src/types/axiosClient.js +0 -2
- package/dist/src/types/btc.d.ts +0 -45
- package/dist/src/types/btc.js +0 -2
- package/dist/src/types/chains.d.ts +0 -3
- package/dist/src/types/chains.js +0 -2
- package/dist/src/types/contract.d.ts +0 -14
- package/dist/src/types/contract.js +0 -2
- package/dist/src/types/eip-2612.d.ts +0 -24
- package/dist/src/types/eip-2612.js +0 -58
- package/dist/src/types/index.d.ts +0 -489
- package/dist/src/types/index.js +0 -8
- package/dist/src/types/permit.d.ts +0 -191
- package/dist/src/types/permit.js +0 -54
- package/dist/src/types/wallet.d.ts +0 -2
- package/dist/src/types/wallet.js +0 -2
- package/dist/src/types/zap/build.d.ts +0 -44
- package/dist/src/types/zap/build.js +0 -2
- package/dist/src/types/zap/index.d.ts +0 -34
- package/dist/src/types/zap/index.js +0 -23
- package/dist/src/types/zap/path.d.ts +0 -33
- package/dist/src/types/zap/path.js +0 -2
- package/dist/src/types/zap/pool.d.ts +0 -39
- package/dist/src/types/zap/pool.js +0 -2
- package/dist/src/types/zap/position.d.ts +0 -27
- package/dist/src/types/zap/position.js +0 -2
- package/dist/src/types/zap/quote.d.ts +0 -7
- package/dist/src/types/zap/quote.js +0 -2
- package/dist/src/types/zap/status.d.ts +0 -28
- package/dist/src/types/zap/status.js +0 -2
- package/dist/src/types/zap/step.d.ts +0 -23
- package/dist/src/types/zap/step.js +0 -2
- package/dist/src/utils/amount.d.ts +0 -82
- package/dist/src/utils/amount.js +0 -71
- package/dist/src/utils/axios.d.ts +0 -13
- package/dist/src/utils/axios.js +0 -42
- package/dist/src/utils/date.d.ts +0 -1
- package/dist/src/utils/date.js +0 -8
- package/dist/src/utils/decoder/swap/abis.d.ts +0 -643
- package/dist/src/utils/decoder/swap/abis.js +0 -831
- package/dist/src/utils/decoder/swap/inputDataDecoder.d.ts +0 -14
- package/dist/src/utils/decoder/swap/inputDataDecoder.js +0 -124
- package/dist/src/utils/eip-2612/eip2612Permit.d.ts +0 -23
- package/dist/src/utils/eip-2612/eip2612Permit.js +0 -121
- package/dist/src/utils/eip-5792/batchApproveTokens.d.ts +0 -21
- package/dist/src/utils/eip-5792/batchApproveTokens.js +0 -49
- package/dist/src/utils/eip-5792/index.d.ts +0 -3
- package/dist/src/utils/eip-5792/index.js +0 -9
- package/dist/src/utils/eip-5792/isBatchTxnSupportedByWallet.d.ts +0 -6
- package/dist/src/utils/eip-5792/isBatchTxnSupportedByWallet.js +0 -22
- package/dist/src/utils/eip-5792/sendBatchCalls.d.ts +0 -10
- package/dist/src/utils/eip-5792/sendBatchCalls.js +0 -25
- package/dist/src/utils/eip-5792/waitForBatchTransactionReceipt.d.ts +0 -4
- package/dist/src/utils/eip-5792/waitForBatchTransactionReceipt.js +0 -26
- package/dist/src/utils/encodeApproveCall.d.ts +0 -6
- package/dist/src/utils/encodeApproveCall.js +0 -13
- package/dist/src/utils/erc20.d.ts +0 -65
- package/dist/src/utils/erc20.js +0 -153
- package/dist/src/utils/errors.d.ts +0 -17
- package/dist/src/utils/errors.js +0 -78
- package/dist/src/utils/index.d.ts +0 -4566
- package/dist/src/utils/index.js +0 -196
- package/dist/src/utils/multicall.d.ts +0 -14
- package/dist/src/utils/multicall.js +0 -25
- package/dist/src/utils/permit2/domain.d.ts +0 -2
- package/dist/src/utils/permit2/domain.js +0 -11
- package/dist/src/utils/permit2/index.d.ts +0 -4
- package/dist/src/utils/permit2/index.js +0 -97
- package/dist/src/utils/permit2/nonce.d.ts +0 -15
- package/dist/src/utils/permit2/nonce.js +0 -61
- package/dist/src/utils/permit2/permitData.d.ts +0 -23
- package/dist/src/utils/permit2/permitData.js +0 -85
- package/dist/src/utils/permit2/values.d.ts +0 -54
- package/dist/src/utils/permit2/values.js +0 -88
- package/dist/src/utils/permit2/witnessData.d.ts +0 -4
- package/dist/src/utils/permit2/witnessData.js +0 -48
- package/dist/src/utils/signIntent/custom.d.ts +0 -11
- package/dist/src/utils/signIntent/custom.js +0 -31
- package/dist/src/utils/signIntent/gasless.d.ts +0 -12
- package/dist/src/utils/signIntent/gasless.js +0 -101
- package/dist/src/utils/signTypedData.d.ts +0 -11
- package/dist/src/utils/signTypedData.js +0 -21
- package/dist/src/utils/tokens.d.ts +0 -8
- package/dist/src/utils/tokens.js +0 -73
- package/dist/src/utils/updateQuotes.d.ts +0 -3
- package/dist/src/utils/updateQuotes.js +0 -69
- package/dist/src/zap/constants/index.d.ts +0 -2
- package/dist/src/zap/constants/index.js +0 -18
- package/dist/src/zap/constants/path.d.ts +0 -8
- package/dist/src/zap/constants/path.js +0 -11
- package/dist/src/zap/constants/step.d.ts +0 -3
- package/dist/src/zap/constants/step.js +0 -6
- package/dist/src/zap/constants/urls.d.ts +0 -13
- package/dist/src/zap/constants/urls.js +0 -16
- package/dist/test/build.test.d.ts +0 -1
- package/dist/test/build.test.js +0 -65
- package/dist/test/permit/permit2Nonce.test.d.ts +0 -2
- package/dist/test/permit/permit2Nonce.test.js +0 -96
- package/dist/test/quotes.test.d.ts +0 -1
- package/dist/test/quotes.test.js +0 -59
- package/dist/test/status.test.d.ts +0 -1
- package/dist/test/status.test.js +0 -37
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const api_1 = require("../api");
|
|
5
|
-
const chains_1 = require("../constants/chains");
|
|
6
|
-
const permit_1 = require("../constants/permit");
|
|
7
|
-
const enums_1 = require("../enums");
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
|
-
const chains_2 = require("../chains");
|
|
10
|
-
const batchApproveTokens_1 = require("../utils/eip-5792/batchApproveTokens");
|
|
11
|
-
const sendBatchCalls_1 = require("../utils/eip-5792/sendBatchCalls");
|
|
12
|
-
const waitForBatchTransactionReceipt_1 = require("../utils/eip-5792/waitForBatchTransactionReceipt");
|
|
13
|
-
const errors_1 = require("../utils/errors");
|
|
14
|
-
const permit_2 = require("./permit");
|
|
15
|
-
const custom_1 = require("../utils/signIntent/custom");
|
|
16
|
-
class TradeTxnHandler {
|
|
17
|
-
}
|
|
18
|
-
_a = TradeTxnHandler;
|
|
19
|
-
TradeTxnHandler.sendTransaction = async (signer, txnParams, chainId, additionalInfo, updatedQuotes) => {
|
|
20
|
-
let txnHash;
|
|
21
|
-
if ((0, utils_1.isTypeSigner)(signer)) {
|
|
22
|
-
const txnRes = await signer.sendTransaction({
|
|
23
|
-
from: txnParams.from,
|
|
24
|
-
to: txnParams.to,
|
|
25
|
-
data: txnParams.data,
|
|
26
|
-
value: txnParams.value,
|
|
27
|
-
gasLimit: txnParams.gasLimit,
|
|
28
|
-
});
|
|
29
|
-
txnHash = txnRes.hash;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
txnHash = await signer.sendTransaction({
|
|
33
|
-
chain: chains_2.viemChainsById[chainId],
|
|
34
|
-
account: txnParams.from,
|
|
35
|
-
to: txnParams.to,
|
|
36
|
-
data: txnParams.data,
|
|
37
|
-
value: BigInt(txnParams.value),
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
status: enums_1.TxnStatus.success,
|
|
42
|
-
code: enums_1.StatusCodes.Success,
|
|
43
|
-
txnHash,
|
|
44
|
-
additionalInfo,
|
|
45
|
-
updatedQuotes,
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
TradeTxnHandler.sendTxnWithBatch = async (request, signer, txnParams, chainId, additionalInfo, updatedQuotes, multicallAddress, rpcUrls) => {
|
|
49
|
-
const approvalBatchCalls = await (0, batchApproveTokens_1.generateApprovalBatchCalls)({
|
|
50
|
-
tokens: request.data.map((token) => ({
|
|
51
|
-
address: token.srcToken,
|
|
52
|
-
amount: token.amount,
|
|
53
|
-
})),
|
|
54
|
-
chainId,
|
|
55
|
-
multicallAddress,
|
|
56
|
-
sender: txnParams.from,
|
|
57
|
-
spender: txnParams.to,
|
|
58
|
-
rpcUrls,
|
|
59
|
-
});
|
|
60
|
-
const batchCalls = [
|
|
61
|
-
...approvalBatchCalls,
|
|
62
|
-
{
|
|
63
|
-
to: txnParams.to,
|
|
64
|
-
data: txnParams.data,
|
|
65
|
-
value: BigInt(txnParams.value),
|
|
66
|
-
},
|
|
67
|
-
];
|
|
68
|
-
if (approvalBatchCalls.length === 0) {
|
|
69
|
-
return _a.sendTransaction(signer, txnParams, chainId, additionalInfo, updatedQuotes);
|
|
70
|
-
}
|
|
71
|
-
const batchResult = await (0, sendBatchCalls_1.sendBatchCalls)(signer, batchCalls);
|
|
72
|
-
if (!batchResult) {
|
|
73
|
-
return {
|
|
74
|
-
status: enums_1.TxnStatus.error,
|
|
75
|
-
errorMsg: 'Batch call failed',
|
|
76
|
-
code: enums_1.StatusCodes.Error,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
console.log('Waiting for batch transaction completion...');
|
|
80
|
-
const receipt = await (0, waitForBatchTransactionReceipt_1.waitForBatchTransactionReceipt)(signer, batchResult.id);
|
|
81
|
-
console.log({ receipt });
|
|
82
|
-
return {
|
|
83
|
-
status: enums_1.TxnStatus.success,
|
|
84
|
-
code: enums_1.StatusCodes.Success,
|
|
85
|
-
txnHash: receipt.transactionHash,
|
|
86
|
-
additionalInfo,
|
|
87
|
-
updatedQuotes,
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
TradeTxnHandler.sendHyperLiquidTransaction = async (signer, txnParams, txnData, chainId, additionalInfo, updatedQuotes) => {
|
|
91
|
-
var _b;
|
|
92
|
-
let txnDetails;
|
|
93
|
-
if (chainId === chains_1.exclusiveChainIds.hyperLiquid) {
|
|
94
|
-
const providerData = additionalInfo ? Object.values(additionalInfo)[0] : null;
|
|
95
|
-
const typedData = providerData && 'typedData' in providerData
|
|
96
|
-
? providerData.typedData
|
|
97
|
-
: null;
|
|
98
|
-
if (!additionalInfo || !typedData) {
|
|
99
|
-
return {
|
|
100
|
-
status: enums_1.TxnStatus.error,
|
|
101
|
-
errorMsg: 'Missing additional info for HyperLiquid transaction',
|
|
102
|
-
code: enums_1.StatusCodes.Error,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
const resp = await (0, custom_1.signCustomTypedData)({
|
|
106
|
-
signer,
|
|
107
|
-
account: txnParams.from,
|
|
108
|
-
domain: typedData.domain,
|
|
109
|
-
types: typedData.types,
|
|
110
|
-
message: typedData.message,
|
|
111
|
-
primaryType: typedData.primaryType,
|
|
112
|
-
});
|
|
113
|
-
if (resp.status !== enums_1.TxnStatus.success) {
|
|
114
|
-
throw new Error('Failed to sign transaction');
|
|
115
|
-
}
|
|
116
|
-
txnDetails = (_b = resp.data) === null || _b === void 0 ? void 0 : _b.signature;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
const resp = await _a.sendTransaction(signer, txnParams, chainId, additionalInfo, updatedQuotes);
|
|
120
|
-
if (resp.status !== enums_1.TxnStatus.success) {
|
|
121
|
-
throw new Error('Failed to sign transaction');
|
|
122
|
-
}
|
|
123
|
-
txnDetails = resp.txnHash;
|
|
124
|
-
}
|
|
125
|
-
const txResp = await (0, api_1.broadcastTradeTx)({
|
|
126
|
-
chainId,
|
|
127
|
-
txData: txnDetails,
|
|
128
|
-
txId: txnData.txId,
|
|
129
|
-
});
|
|
130
|
-
if (txResp.status !== enums_1.TxnStatus.success) {
|
|
131
|
-
throw new Error('Failed to broadcast or save transaction');
|
|
132
|
-
}
|
|
133
|
-
return {
|
|
134
|
-
status: enums_1.TxnStatus.success,
|
|
135
|
-
code: enums_1.StatusCodes.Success,
|
|
136
|
-
txnHash: txResp.txnHash,
|
|
137
|
-
additionalInfo,
|
|
138
|
-
updatedQuotes,
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
TradeTxnHandler.buildAndSendTransaction = async ({ request, signer, txnData, multicallAddress, batchTransaction = false, rpcUrls, }) => {
|
|
142
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
143
|
-
try {
|
|
144
|
-
const chainId = request.fromChain;
|
|
145
|
-
let buildTxnResponseData;
|
|
146
|
-
if (txnData) {
|
|
147
|
-
buildTxnResponseData = txnData;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
buildTxnResponseData = await (0, api_1.fetchTradeBuildTxnData)(request);
|
|
151
|
-
}
|
|
152
|
-
const { data, from, to, value, gasLimit, additionalInfo, updatedQuotes } = buildTxnResponseData;
|
|
153
|
-
const txnParams = { from, to: to, data, value: value, gasLimit: gasLimit };
|
|
154
|
-
if ([chainId, ...request.data.map((e) => e.toChain)].some((chain) => chain === chains_1.exclusiveChainIds.hyperLiquid)) {
|
|
155
|
-
return _a.sendHyperLiquidTransaction(signer, txnParams, buildTxnResponseData, chainId, additionalInfo, updatedQuotes);
|
|
156
|
-
}
|
|
157
|
-
if (batchTransaction && !(0, utils_1.isTypeSigner)(signer)) {
|
|
158
|
-
return _a.sendTxnWithBatch(request, signer, txnParams, chainId, additionalInfo, updatedQuotes, multicallAddress, rpcUrls);
|
|
159
|
-
}
|
|
160
|
-
console.log('Using viem walletClient - sending regular transaction.');
|
|
161
|
-
return _a.sendTransaction(signer, txnParams, chainId, additionalInfo, updatedQuotes);
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
console.log({ error });
|
|
165
|
-
if ((0, errors_1.isAxiosError)(error)) {
|
|
166
|
-
if (((_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.status) === enums_1.StatusCodes.SimulationFailure) {
|
|
167
|
-
return {
|
|
168
|
-
status: enums_1.TxnStatus.error,
|
|
169
|
-
errorMsg: 'Simulation Failed',
|
|
170
|
-
error: ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data).message,
|
|
171
|
-
code: ((_d = error.response) === null || _d === void 0 ? void 0 : _d.data).code,
|
|
172
|
-
action: ((_e = error.response) === null || _e === void 0 ? void 0 : _e.data).action,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
return {
|
|
176
|
-
status: enums_1.TxnStatus.error,
|
|
177
|
-
errorMsg: 'Params Failed: ' + JSON.stringify((_g = (_f = error === null || error === void 0 ? void 0 : error.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.message),
|
|
178
|
-
error: (_j = (_h = error === null || error === void 0 ? void 0 : error.response) === null || _h === void 0 ? void 0 : _h.data) !== null && _j !== void 0 ? _j : error,
|
|
179
|
-
code: (_l = (_k = error === null || error === void 0 ? void 0 : error.response) === null || _k === void 0 ? void 0 : _k.status) !== null && _l !== void 0 ? _l : enums_1.StatusCodes.Error,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
return (0, errors_1.handleViemTransactionError)({ error });
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
TradeTxnHandler.buildGaslessTxAndSignPermit = async ({ request, signer, rpcUrls, spender, txnData, }) => {
|
|
186
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
187
|
-
try {
|
|
188
|
-
const chainId = request.fromChain;
|
|
189
|
-
let buildTxnResponseData;
|
|
190
|
-
if (txnData) {
|
|
191
|
-
buildTxnResponseData = txnData;
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
buildTxnResponseData = await (0, api_1.fetchTradeBuildTxnData)(Object.assign(Object.assign({}, request), { gasless: true }));
|
|
195
|
-
}
|
|
196
|
-
const permitType = request.hasPermit2ApprovalForAllTokens ? permit_1.PermitTypes.PermitBatchWitnessTransferFrom : permit_1.PermitTypes.EIP2612Permit;
|
|
197
|
-
const txId = buildTxnResponseData.txId;
|
|
198
|
-
const resp = await permit_2.default.signGaslessUserIntent(Object.assign({ tokens: request.data.map((req, index) => {
|
|
199
|
-
return {
|
|
200
|
-
address: req.srcToken,
|
|
201
|
-
amount: req.amount,
|
|
202
|
-
index: index,
|
|
203
|
-
};
|
|
204
|
-
}), chainId,
|
|
205
|
-
rpcUrls, sender: request.sender, spender,
|
|
206
|
-
permitType,
|
|
207
|
-
signer, gasless: true, txId, service: 'trade', contractVersion: enums_1.ContractVersion.v2 }, buildTxnResponseData.transaction));
|
|
208
|
-
if (resp.status === enums_1.TxnStatus.success && resp.data) {
|
|
209
|
-
const permit = resp.data.type === permit_1.PermitTypes.EIP2612Permit
|
|
210
|
-
? {
|
|
211
|
-
permitData: request.data.map((req) => {
|
|
212
|
-
return {
|
|
213
|
-
token: req.srcToken,
|
|
214
|
-
amount: req.amount,
|
|
215
|
-
permit: req.permitData,
|
|
216
|
-
};
|
|
217
|
-
}),
|
|
218
|
-
gaslessIntentNonce: (_b = resp.data.nonce) === null || _b === void 0 ? void 0 : _b.toString(),
|
|
219
|
-
gaslessIntentSignature: resp.data.signature,
|
|
220
|
-
gaslessIntentDeadline: (_c = resp.data.deadline) === null || _c === void 0 ? void 0 : _c.toString(),
|
|
221
|
-
}
|
|
222
|
-
: {
|
|
223
|
-
batchPermitData: resp.data.batchPermitData,
|
|
224
|
-
};
|
|
225
|
-
const gaslessTxResp = await (0, api_1.executeGaslessTxnData)({
|
|
226
|
-
chainId: request.fromChain,
|
|
227
|
-
txId,
|
|
228
|
-
permit,
|
|
229
|
-
});
|
|
230
|
-
if (gaslessTxResp.status !== enums_1.TxnStatus.success) {
|
|
231
|
-
throw new Error('Failed to execute gasless transaction');
|
|
232
|
-
}
|
|
233
|
-
return {
|
|
234
|
-
status: enums_1.TxnStatus.success,
|
|
235
|
-
code: enums_1.StatusCodes.Success,
|
|
236
|
-
txnHash: gaslessTxResp.txnHash,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
throw new Error('Gasless Transaction Failed');
|
|
240
|
-
}
|
|
241
|
-
catch (error) {
|
|
242
|
-
console.log({ error });
|
|
243
|
-
if ((0, errors_1.isAxiosError)(error)) {
|
|
244
|
-
if (((_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.status) === enums_1.StatusCodes.SimulationFailure) {
|
|
245
|
-
return {
|
|
246
|
-
status: enums_1.TxnStatus.error,
|
|
247
|
-
errorMsg: 'Simulation Failed',
|
|
248
|
-
error: ((_e = error.response) === null || _e === void 0 ? void 0 : _e.data).message,
|
|
249
|
-
code: ((_f = error.response) === null || _f === void 0 ? void 0 : _f.data).code,
|
|
250
|
-
action: ((_g = error.response) === null || _g === void 0 ? void 0 : _g.data).action,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
status: enums_1.TxnStatus.error,
|
|
255
|
-
errorMsg: 'Params Failed: ' + JSON.stringify((_j = (_h = error === null || error === void 0 ? void 0 : error.response) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.message),
|
|
256
|
-
error: (_l = (_k = error === null || error === void 0 ? void 0 : error.response) === null || _k === void 0 ? void 0 : _k.data) !== null && _l !== void 0 ? _l : error,
|
|
257
|
-
code: (_o = (_m = error === null || error === void 0 ? void 0 : error.response) === null || _m === void 0 ? void 0 : _m.status) !== null && _o !== void 0 ? _o : enums_1.StatusCodes.Error,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
return (0, errors_1.handleViemTransactionError)({ error });
|
|
261
|
-
}
|
|
262
|
-
};
|
|
263
|
-
exports.default = TradeTxnHandler;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Signer } from 'ethers';
|
|
2
|
-
import { WalletClient } from 'viem';
|
|
3
|
-
import { StatusCodes, TxnStatus } from '../enums';
|
|
4
|
-
import { DZapTransactionResponse, HexString } from '../types';
|
|
5
|
-
import { ZapBuildTxnRequest } from '../types/zap';
|
|
6
|
-
import { ZapStep, ZapEvmTxnDetails } from '../types/zap/step';
|
|
7
|
-
declare class ZapTxnHandler {
|
|
8
|
-
static execute: ({ chainId, txnData, signer, }: {
|
|
9
|
-
chainId: number;
|
|
10
|
-
txnData: ZapEvmTxnDetails;
|
|
11
|
-
signer: Signer | WalletClient;
|
|
12
|
-
}) => Promise<DZapTransactionResponse>;
|
|
13
|
-
static approve: ({ chainId, data, signer }: {
|
|
14
|
-
chainId: number;
|
|
15
|
-
data: ZapEvmTxnDetails;
|
|
16
|
-
signer: Signer | WalletClient;
|
|
17
|
-
}) => Promise<{
|
|
18
|
-
status: TxnStatus;
|
|
19
|
-
error: any;
|
|
20
|
-
errorMsg: any;
|
|
21
|
-
code: StatusCodes;
|
|
22
|
-
} | {
|
|
23
|
-
status: TxnStatus;
|
|
24
|
-
code: StatusCodes;
|
|
25
|
-
txnHash: HexString;
|
|
26
|
-
}>;
|
|
27
|
-
static zap: ({ request, steps, signer, }: {
|
|
28
|
-
request: ZapBuildTxnRequest;
|
|
29
|
-
steps?: ZapStep[];
|
|
30
|
-
signer: Signer | WalletClient;
|
|
31
|
-
}) => Promise<{
|
|
32
|
-
status: TxnStatus.success;
|
|
33
|
-
code: StatusCodes | number;
|
|
34
|
-
txnHash: HexString;
|
|
35
|
-
} | DZapTransactionResponse>;
|
|
36
|
-
}
|
|
37
|
-
export default ZapTxnHandler;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const api_1 = require("../api");
|
|
5
|
-
const enums_1 = require("../enums");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
7
|
-
const chains_1 = require("../chains");
|
|
8
|
-
const errors_1 = require("../utils/errors");
|
|
9
|
-
const step_1 = require("../zap/constants/step");
|
|
10
|
-
class ZapTxnHandler {
|
|
11
|
-
}
|
|
12
|
-
_a = ZapTxnHandler;
|
|
13
|
-
ZapTxnHandler.execute = async ({ chainId, txnData, signer, }) => {
|
|
14
|
-
var _b;
|
|
15
|
-
try {
|
|
16
|
-
const { callData, callTo, value, estimatedGas } = txnData;
|
|
17
|
-
if ((0, utils_1.isTypeSigner)(signer)) {
|
|
18
|
-
console.log('Using ethers signer.');
|
|
19
|
-
const from = await signer.getAddress();
|
|
20
|
-
const txnRes = await signer.sendTransaction({
|
|
21
|
-
from,
|
|
22
|
-
to: callTo,
|
|
23
|
-
data: callData,
|
|
24
|
-
value: BigInt(value),
|
|
25
|
-
gasLimit: BigInt(estimatedGas) ? BigInt(estimatedGas) : undefined,
|
|
26
|
-
});
|
|
27
|
-
return {
|
|
28
|
-
status: enums_1.TxnStatus.success,
|
|
29
|
-
code: enums_1.StatusCodes.Success,
|
|
30
|
-
txnHash: txnRes.hash,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
console.log('Using viem walletClient.');
|
|
35
|
-
const txnHash = await signer.sendTransaction({
|
|
36
|
-
chain: chains_1.viemChainsById[chainId],
|
|
37
|
-
account: (_b = signer.account) === null || _b === void 0 ? void 0 : _b.address,
|
|
38
|
-
to: txnData.callTo,
|
|
39
|
-
data: txnData.callData,
|
|
40
|
-
value: BigInt(txnData.value),
|
|
41
|
-
});
|
|
42
|
-
return {
|
|
43
|
-
status: enums_1.TxnStatus.success,
|
|
44
|
-
code: enums_1.StatusCodes.Success,
|
|
45
|
-
txnHash,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
console.log({ error });
|
|
51
|
-
return (0, errors_1.handleViemTransactionError)({ error });
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
ZapTxnHandler.approve = async ({ chainId, data, signer }) => {
|
|
55
|
-
var _b;
|
|
56
|
-
try {
|
|
57
|
-
const { callData, callTo, value, estimatedGas } = data;
|
|
58
|
-
const publicClient = (0, utils_1.getPublicClient)({ chainId, rpcUrls: undefined });
|
|
59
|
-
const blockNumber = await publicClient.getBlockNumber();
|
|
60
|
-
console.log('block Number and data');
|
|
61
|
-
console.dir(Object.assign({ blockNumber }, data), { depth: null });
|
|
62
|
-
if ((0, utils_1.isTypeSigner)(signer)) {
|
|
63
|
-
console.log('Using ethers signer.');
|
|
64
|
-
const from = await signer.getAddress();
|
|
65
|
-
const txnRes = await signer.sendTransaction({
|
|
66
|
-
from,
|
|
67
|
-
to: callTo,
|
|
68
|
-
data: callData,
|
|
69
|
-
value: BigInt(value),
|
|
70
|
-
gasLimit: BigInt(estimatedGas) ? BigInt(estimatedGas) : undefined,
|
|
71
|
-
});
|
|
72
|
-
return {
|
|
73
|
-
status: enums_1.TxnStatus.success,
|
|
74
|
-
code: enums_1.StatusCodes.Success,
|
|
75
|
-
txnHash: txnRes.hash,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
console.log('Using viem walletClient.');
|
|
80
|
-
const txnHash = await signer.sendTransaction({
|
|
81
|
-
chain: chains_1.viemChainsById[chainId],
|
|
82
|
-
account: (_b = signer.account) === null || _b === void 0 ? void 0 : _b.address,
|
|
83
|
-
to: data.callTo,
|
|
84
|
-
data: data.callData,
|
|
85
|
-
value: BigInt(data.value),
|
|
86
|
-
});
|
|
87
|
-
return {
|
|
88
|
-
status: enums_1.TxnStatus.success,
|
|
89
|
-
code: enums_1.StatusCodes.Success,
|
|
90
|
-
txnHash,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
console.log({ error });
|
|
96
|
-
return (0, errors_1.handleViemTransactionError)({ error });
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
ZapTxnHandler.zap = async ({ request, steps, signer, }) => {
|
|
100
|
-
try {
|
|
101
|
-
const { srcChainId: chainId } = request;
|
|
102
|
-
if (!steps || steps.length === 0) {
|
|
103
|
-
const route = (await (0, api_1.fetchZapBuildTxnData)(request)).data;
|
|
104
|
-
steps = route.steps;
|
|
105
|
-
if (!steps || steps.length === 0) {
|
|
106
|
-
return {
|
|
107
|
-
status: enums_1.TxnStatus.error,
|
|
108
|
-
code: enums_1.StatusCodes.FunctionNotFound,
|
|
109
|
-
errorMsg: 'No steps found in the zap route.',
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
let txnHash;
|
|
114
|
-
for (let i = 0; i < steps.length; i++) {
|
|
115
|
-
const step = steps[i];
|
|
116
|
-
if (step.action === step_1.zapStepAction.execute) {
|
|
117
|
-
const result = await _a.execute({ chainId, txnData: step.data, signer });
|
|
118
|
-
if (result.status !== enums_1.TxnStatus.success) {
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
|
-
txnHash = result.txnHash;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
status: enums_1.TxnStatus.success,
|
|
126
|
-
code: enums_1.StatusCodes.Success,
|
|
127
|
-
txnHash,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
console.log({ error });
|
|
132
|
-
return (0, errors_1.handleViemTransactionError)({ error });
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
exports.default = ZapTxnHandler;
|
package/dist/src/types/btc.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export type Witness = {
|
|
2
|
-
value: number;
|
|
3
|
-
script: string;
|
|
4
|
-
};
|
|
5
|
-
type PsbtInputP2PKH = {
|
|
6
|
-
scriptType: 'p2pkh';
|
|
7
|
-
nonWitnessUtxo: Buffer;
|
|
8
|
-
redeemScript?: never;
|
|
9
|
-
};
|
|
10
|
-
type PsbtInputP2SH = {
|
|
11
|
-
scriptType: 'p2sh';
|
|
12
|
-
witnessUtxo: Witness;
|
|
13
|
-
redeemScript: Buffer;
|
|
14
|
-
redeemScriptArgumentByteLengths?: number[];
|
|
15
|
-
};
|
|
16
|
-
type PsbtInputP2WPKH = {
|
|
17
|
-
scriptType: 'p2wpkh';
|
|
18
|
-
witnessUtxo: Witness;
|
|
19
|
-
redeemScript?: never;
|
|
20
|
-
};
|
|
21
|
-
type PsbtInputP2WSH = {
|
|
22
|
-
scriptType: 'p2wsh';
|
|
23
|
-
witnessUtxo: Witness;
|
|
24
|
-
witnessScript: Buffer;
|
|
25
|
-
};
|
|
26
|
-
type PsbtInputP2TR = {
|
|
27
|
-
scriptType: 'p2tr';
|
|
28
|
-
witnessUtxo: Witness;
|
|
29
|
-
tapInternalKey: Buffer;
|
|
30
|
-
};
|
|
31
|
-
export type PsbtInput = {
|
|
32
|
-
hash: string;
|
|
33
|
-
index: number;
|
|
34
|
-
sequence: number;
|
|
35
|
-
value: number;
|
|
36
|
-
} & (PsbtInputP2PKH | PsbtInputP2SH | PsbtInputP2WPKH | PsbtInputP2TR | PsbtInputP2WSH);
|
|
37
|
-
export type PsbtOutput = {
|
|
38
|
-
address: string;
|
|
39
|
-
script?: Buffer;
|
|
40
|
-
value: number;
|
|
41
|
-
} | {
|
|
42
|
-
script: string;
|
|
43
|
-
value: number;
|
|
44
|
-
};
|
|
45
|
-
export {};
|
package/dist/src/types/btc.js
DELETED
package/dist/src/types/chains.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AvailableDZapServices } from '.';
|
|
2
|
-
import { Versions } from '../enums';
|
|
3
|
-
export type ContractConfig = {
|
|
4
|
-
[serviceKey in AvailableDZapServices]: {
|
|
5
|
-
[versionKey in Versions]?: {
|
|
6
|
-
address: ContractAddress;
|
|
7
|
-
abi: string;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export type ContractAddress = {
|
|
12
|
-
otherChains: string;
|
|
13
|
-
zkSync: string;
|
|
14
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare const EIP2612DefaultTypes: {
|
|
2
|
-
Permit: {
|
|
3
|
-
name: string;
|
|
4
|
-
type: string;
|
|
5
|
-
}[];
|
|
6
|
-
};
|
|
7
|
-
export declare const DzapUserIntentSwapTypes: {
|
|
8
|
-
SignedGasLessSwapData: {
|
|
9
|
-
name: string;
|
|
10
|
-
type: string;
|
|
11
|
-
}[];
|
|
12
|
-
};
|
|
13
|
-
export declare const DzapUserIntentBridgeTypes: {
|
|
14
|
-
SignedGasLessBridgeData: {
|
|
15
|
-
name: string;
|
|
16
|
-
type: string;
|
|
17
|
-
}[];
|
|
18
|
-
};
|
|
19
|
-
export declare const DzapUserIntentSwapBridgeTypes: {
|
|
20
|
-
SignedGasLessSwapBridgeData: {
|
|
21
|
-
name: string;
|
|
22
|
-
type: string;
|
|
23
|
-
}[];
|
|
24
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DzapUserIntentSwapBridgeTypes = exports.DzapUserIntentBridgeTypes = exports.DzapUserIntentSwapTypes = exports.EIP2612DefaultTypes = void 0;
|
|
4
|
-
exports.EIP2612DefaultTypes = {
|
|
5
|
-
Permit: [
|
|
6
|
-
{
|
|
7
|
-
name: 'owner',
|
|
8
|
-
type: 'address',
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
name: 'spender',
|
|
12
|
-
type: 'address',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: 'value',
|
|
16
|
-
type: 'uint256',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: 'nonce',
|
|
20
|
-
type: 'uint256',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
name: 'deadline',
|
|
24
|
-
type: 'uint256',
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
};
|
|
28
|
-
exports.DzapUserIntentSwapTypes = {
|
|
29
|
-
SignedGasLessSwapData: [
|
|
30
|
-
{ name: 'txId', type: 'bytes32' },
|
|
31
|
-
{ name: 'user', type: 'address' },
|
|
32
|
-
{ name: 'nonce', type: 'uint256' },
|
|
33
|
-
{ name: 'deadline', type: 'uint256' },
|
|
34
|
-
{ name: 'executorFeesHash', type: 'bytes32' },
|
|
35
|
-
{ name: 'swapDataHash', type: 'bytes32' },
|
|
36
|
-
],
|
|
37
|
-
};
|
|
38
|
-
exports.DzapUserIntentBridgeTypes = {
|
|
39
|
-
SignedGasLessBridgeData: [
|
|
40
|
-
{ name: 'txId', type: 'bytes32' },
|
|
41
|
-
{ name: 'user', type: 'address' },
|
|
42
|
-
{ name: 'nonce', type: 'uint256' },
|
|
43
|
-
{ name: 'deadline', type: 'uint256' },
|
|
44
|
-
{ name: 'executorFeesHash', type: 'bytes32' },
|
|
45
|
-
{ name: 'adapterDataHash', type: 'bytes32' },
|
|
46
|
-
],
|
|
47
|
-
};
|
|
48
|
-
exports.DzapUserIntentSwapBridgeTypes = {
|
|
49
|
-
SignedGasLessSwapBridgeData: [
|
|
50
|
-
{ name: 'txId', type: 'bytes32' },
|
|
51
|
-
{ name: 'user', type: 'address' },
|
|
52
|
-
{ name: 'nonce', type: 'uint256' },
|
|
53
|
-
{ name: 'deadline', type: 'uint256' },
|
|
54
|
-
{ name: 'executorFeesHash', type: 'bytes32' },
|
|
55
|
-
{ name: 'swapDataHash', type: 'bytes32' },
|
|
56
|
-
{ name: 'adapterDataHash', type: 'bytes32' },
|
|
57
|
-
],
|
|
58
|
-
};
|