@dzapio/sdk 1.0.1
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/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +355 -0
- package/dist/api/index.d.ts +19 -0
- package/dist/artifacts/ERC20Permit.d.ts +336 -0
- package/dist/artifacts/Permit2.d.ts +700 -0
- package/dist/artifacts/default/DZapCoreAbi.d.ts +2 -0
- package/dist/artifacts/default/DZapDcaAbi.d.ts +2 -0
- package/dist/artifacts/default/Permit2Abi.d.ts +70 -0
- package/dist/artifacts/default/erc20Abi.d.ts +165 -0
- package/dist/artifacts/default/index.d.ts +5 -0
- package/dist/artifacts/index.d.ts +2 -0
- package/dist/artifacts/staging/DZapCoreSwapAbi.d.ts +2 -0
- package/dist/artifacts/staging/index.d.ts +2 -0
- package/dist/axios/baseClient.d.ts +2 -0
- package/dist/axios/index.d.ts +8 -0
- package/dist/config.d.ts +16 -0
- package/dist/constants/address.d.ts +13 -0
- package/dist/constants/approval.d.ts +5 -0
- package/dist/constants/axios.d.ts +2 -0
- package/dist/constants/chains.d.ts +16 -0
- package/dist/constants/contract.d.ts +6 -0
- package/dist/constants/erc20.d.ts +22 -0
- package/dist/constants/httpMethods.d.ts +2 -0
- package/dist/constants/index.d.ts +43 -0
- package/dist/constants/permit.d.ts +5 -0
- package/dist/constants/permit2.d.ts +2 -0
- package/dist/constants/rpc.d.ts +2 -0
- package/dist/constants/urlConstants.d.ts +13 -0
- package/dist/dZapClient/index.d.ts +383 -0
- package/dist/enums/index.d.ts +36 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.m.js +2 -0
- package/dist/index.m.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/service/cache/cacheProvider.d.ts +10 -0
- package/dist/service/cache/constant.d.ts +2 -0
- package/dist/service/price/index.d.ts +16 -0
- package/dist/service/price/provider/coingecko/config.d.ts +6 -0
- package/dist/service/price/provider/coingecko/index.d.ts +9 -0
- package/dist/service/price/provider/defiLlama/config.d.ts +3 -0
- package/dist/service/price/provider/defiLlama/index.d.ts +9 -0
- package/dist/service/price/provider/defiLlama/types.d.ts +11 -0
- package/dist/service/price/provider/dzap/index.d.ts +6 -0
- package/dist/service/price/types/IPriceProvider.d.ts +14 -0
- package/dist/transactionHandlers/generic.d.ts +24 -0
- package/dist/transactionHandlers/permit.d.ts +58 -0
- package/dist/transactionHandlers/trade.d.ts +11 -0
- package/dist/transactionHandlers/zap.d.ts +37 -0
- package/dist/types/axiosClient.d.ts +6 -0
- package/dist/types/btc.d.ts +45 -0
- package/dist/types/chains.d.ts +2 -0
- package/dist/types/contract.d.ts +14 -0
- package/dist/types/eip-2612.d.ts +6 -0
- package/dist/types/index.d.ts +317 -0
- package/dist/types/zap/index.d.ts +65 -0
- package/dist/types/zap/path.d.ts +36 -0
- package/dist/types/zap/step.d.ts +15 -0
- package/dist/utils/amount.d.ts +82 -0
- package/dist/utils/axios.d.ts +13 -0
- package/dist/utils/chains.d.ts +2 -0
- package/dist/utils/date.d.ts +1 -0
- package/dist/utils/erc20.d.ts +61 -0
- package/dist/utils/errors.d.ts +16 -0
- package/dist/utils/index.d.ts +3940 -0
- package/dist/utils/multicall.d.ts +12 -0
- package/dist/utils/permit/permit2Methods.d.ts +32 -0
- package/dist/utils/permit/permitMethods.d.ts +29 -0
- package/dist/utils/signTypedData.d.ts +11 -0
- package/dist/utils/tokens.d.ts +7 -0
- package/dist/utils/updateQuotes.d.ts +3 -0
- package/dist/zap/constants/index.d.ts +2 -0
- package/dist/zap/constants/path.d.ts +8 -0
- package/dist/zap/constants/step.d.ts +3 -0
- package/dist/zap/constants/urls.d.ts +3 -0
- package/package.json +115 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2025-07-XX
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of DZap SDK
|
|
12
|
+
- Support for swap and bridge operations
|
|
13
|
+
- Zap operations for multi-step transactions
|
|
14
|
+
- Token utilities for fetching token lists, details, and prices
|
|
15
|
+
- Chain utilities for fetching supported chains
|
|
16
|
+
- Permit utilities for gas-less approvals (Permit2)
|
|
17
|
+
- Comprehensive TypeScript support
|
|
18
|
+
- Full documentation and examples
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
- `getQuotes()` - Fetch quotes for swaps and bridges
|
|
22
|
+
- `buildTxn()` - Build transaction payloads
|
|
23
|
+
- `buildAndSendTransaction()` - Build and send transactions in one step
|
|
24
|
+
- `getStatus()` - Check transaction status
|
|
25
|
+
- `zap()` - Execute multi-step Zap operations
|
|
26
|
+
- `getZapQuote()` - Get quotes for Zap operations
|
|
27
|
+
- `getAllTokens()` - Fetch all tokens for a chain
|
|
28
|
+
- `getTokenDetails()` - Get detailed token information
|
|
29
|
+
- `getTokenPrices()` - Fetch token prices
|
|
30
|
+
- `getAllSupportedChains()` - Get supported blockchain networks
|
|
31
|
+
- `getPermitAllowance()` - Check Permit2 allowances
|
|
32
|
+
- `approvePermit()` - Approve tokens via Permit2
|
|
33
|
+
- `sign()` - Sign permit data for gas-less approvals
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 DZap
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
# DZap SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript/JavaScript SDK for interacting with the DZap protocol, providing utilities for DeFi operations such as swaps, bridges, and Zaps. This SDK abstracts away the complexity of contract interactions, token management, and price fetching, making it easy to build on top of DZap.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @dzapio/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @dzapio/sdk
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @dzapio/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Table of Contents
|
|
18
|
+
|
|
19
|
+
- [Installation](#installation)
|
|
20
|
+
- [Initialization](#initialization)
|
|
21
|
+
- [Client Methods](#client-methods)
|
|
22
|
+
- [Trade Operations](#trade-operations)
|
|
23
|
+
- [Trade Quotes](#trade-quotes)
|
|
24
|
+
- [Build Trade Transaction](#build-trade-transaction)
|
|
25
|
+
- [Trade](#trade)
|
|
26
|
+
- [Get Trade Transaction Status](#get-trade-transaction-status)
|
|
27
|
+
- [Zap Operations](#zap-operations)
|
|
28
|
+
- [Get Zap Quote](#get-zap-quote)
|
|
29
|
+
- [Build Zap Transaction](#build-zap-transaction)
|
|
30
|
+
- [Zap](#zap)
|
|
31
|
+
- [Get Zap Transaction Status](#get-zap-transaction-status)
|
|
32
|
+
- [Token Utilities](#token-utilities)
|
|
33
|
+
- [Chain Utilities](#chain-utilities)
|
|
34
|
+
- [Approval and Signature Utilities](#approval-and-signature-utilities)
|
|
35
|
+
- [Token Approval Mechanism](#token-approval-mechanism)
|
|
36
|
+
- [Types](#types)
|
|
37
|
+
- [License](#license)
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Initialization
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { DZapClient } from '@dzapio/sdk';
|
|
45
|
+
|
|
46
|
+
// Basic initialization
|
|
47
|
+
const dZap = DZapClient.getInstance();
|
|
48
|
+
|
|
49
|
+
// With custom RPC URLs (optional)
|
|
50
|
+
const customRpcUrls = {
|
|
51
|
+
1: ['https://eth.llamarpc.com'], // Ethereum mainnet
|
|
52
|
+
42161: ['https://arbitrum.llamarpc.com'], // Arbitrum
|
|
53
|
+
// Add more chains as needed
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Initialize with custom RPC URLs
|
|
57
|
+
// This is useful if you want to use specific RPC endpoints instead of the defaults.
|
|
58
|
+
const dZapWithCustomRpc = DZapClient.getInstance(customRpcUrls);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Client Methods
|
|
64
|
+
|
|
65
|
+
### Trade Operations
|
|
66
|
+
|
|
67
|
+
#### Trade Quotes
|
|
68
|
+
|
|
69
|
+
##### `getTradeQuotes(request: TradeQuotesRequest): Promise<TradeQuotesResponse>`
|
|
70
|
+
|
|
71
|
+
- **Purpose:** Fetches quotes for swaps, bridges, or other DZap services.
|
|
72
|
+
- **Input:**
|
|
73
|
+
- `request`: `TradeQuotesRequest` (object with details like source/destination tokens, amounts, chains, etc.)
|
|
74
|
+
- **Output:**
|
|
75
|
+
- `Promise<TradeQuotesResponse>` (object containing available quotes, rates, fees, etc.)
|
|
76
|
+
- **Description:**
|
|
77
|
+
Returns the best available quotes for the requested operation, with prices updated using the SDK's price service.
|
|
78
|
+
|
|
79
|
+
#### Build Trade Transaction
|
|
80
|
+
|
|
81
|
+
> **Note:** This method requires token approval. See [Token Approval Mechanism](#token-approval-mechanism).
|
|
82
|
+
|
|
83
|
+
##### `buildTradeTxn(request: TradeBuildTxnRequest): Promise<TradeBuildTxnResponse>`
|
|
84
|
+
|
|
85
|
+
- **Purpose:** Builds a transaction payload for a swap, bridge, or other operation.
|
|
86
|
+
- **Input:**
|
|
87
|
+
- `request`: `TradeBuildTxnRequest` (object with operation details)
|
|
88
|
+
- **Output:**
|
|
89
|
+
- `Promise<TradeBuildTxnResponse>` (transaction data ready to be signed/sent)
|
|
90
|
+
- **Description:**
|
|
91
|
+
Prepares the transaction data required to execute the requested operation on-chain.
|
|
92
|
+
|
|
93
|
+
#### Trade
|
|
94
|
+
|
|
95
|
+
> **Note:** This method requires token approval. See [Token Approval Mechanism](#token-approval-mechanism).
|
|
96
|
+
|
|
97
|
+
##### `trade({ request, signer, txnData })`
|
|
98
|
+
|
|
99
|
+
- **Purpose:** Builds and sends a trade transaction in one step.
|
|
100
|
+
- **Input:**
|
|
101
|
+
- `request`: `TradeBuildTxnRequest`
|
|
102
|
+
- `signer`: `Signer` or `WalletClient`
|
|
103
|
+
- `txnData?`: `TradeBuildTxnResponse`
|
|
104
|
+
- **Output:**
|
|
105
|
+
- Transaction result
|
|
106
|
+
- **Description:**
|
|
107
|
+
Combines building and sending a transaction for convenience.
|
|
108
|
+
|
|
109
|
+
#### Get Trade Transaction Status
|
|
110
|
+
|
|
111
|
+
##### `getTradeTxnStatus({ txHash, txIds, chainId }): Promise<TradeStatusResponse | Record<string, TradeStatusResponse>>`
|
|
112
|
+
|
|
113
|
+
- **Purpose:** Fetches the status of a trade transaction (swap/bridge).
|
|
114
|
+
- **Input:**
|
|
115
|
+
- `txHash?`: string (transaction hash)
|
|
116
|
+
- `txIds?`: string (comma-separated list of `srcChainId-txHash`)
|
|
117
|
+
- `chainId?`: string (chain ID)
|
|
118
|
+
- **Note:** Either `txIds` OR both `txHash` and `chainId` must be provided.
|
|
119
|
+
- **Output:**
|
|
120
|
+
- `Promise<TradeStatusResponse | Record<string, TradeStatusResponse>>`
|
|
121
|
+
- **Description:**
|
|
122
|
+
Returns the status (pending, completed, failed) of one or more transactions.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
### Zap Operations
|
|
127
|
+
|
|
128
|
+
#### Get Zap Quote
|
|
129
|
+
|
|
130
|
+
##### `getZapQuote(request: ZapQuoteRequest): Promise<ZapQuoteResponse>`
|
|
131
|
+
|
|
132
|
+
- **Purpose:** Fetches a quote for a Zap operation.
|
|
133
|
+
- **Input:**
|
|
134
|
+
- `request`: ZapQuoteRequest
|
|
135
|
+
- **Output:**
|
|
136
|
+
- `Promise<ZapQuoteResponse>`
|
|
137
|
+
- **Description:**
|
|
138
|
+
Returns the best available quote for the requested Zap.
|
|
139
|
+
|
|
140
|
+
#### Build Zap Transaction
|
|
141
|
+
|
|
142
|
+
##### `buildZapTxn(request: ZapBuildTxnRequest): Promise<ZapBuildTxnResponse>`
|
|
143
|
+
|
|
144
|
+
- **Purpose:** Builds a zap transaction with detailed steps for execution.
|
|
145
|
+
- **Input:**
|
|
146
|
+
- `request`: ZapBuildTxnRequest
|
|
147
|
+
- **Output:**
|
|
148
|
+
- `Promise<ZapBuildTxnResponse>`
|
|
149
|
+
- **Description:**
|
|
150
|
+
Prepares the transaction steps required to execute the requested Zap operation on-chain.
|
|
151
|
+
|
|
152
|
+
#### Zap
|
|
153
|
+
|
|
154
|
+
> **Note:** This method requires token approval. See [Token Approval Mechanism](#token-approval-mechanism).
|
|
155
|
+
|
|
156
|
+
##### `zap({ request, signer, steps })`
|
|
157
|
+
|
|
158
|
+
- **Purpose:** Builds and sends a zap transaction in one step.
|
|
159
|
+
- **Input:**
|
|
160
|
+
- `request`: ZapBuildTxnRequest
|
|
161
|
+
- `signer`: WalletClient | Signer
|
|
162
|
+
- `steps?`: ZapTransactionStep[] (optional, will build if not provided)
|
|
163
|
+
- **Output:**
|
|
164
|
+
- Transaction result
|
|
165
|
+
- **Description:**
|
|
166
|
+
Runs a series of Zap steps as a single operation, building steps from request if not provided.
|
|
167
|
+
|
|
168
|
+
#### Get Zap Transaction Status
|
|
169
|
+
|
|
170
|
+
##### `getZapTxnStatus(request: ZapTxnStatusRequest): Promise<ZapTxnStatusResponse>`
|
|
171
|
+
|
|
172
|
+
- **Purpose:** Fetches the status of a Zap transaction.
|
|
173
|
+
- **Input:**
|
|
174
|
+
- `request`: ZapTxnStatusRequest
|
|
175
|
+
- **Output:**
|
|
176
|
+
- `Promise<ZapTxnStatusResponse>`
|
|
177
|
+
- **Description:**
|
|
178
|
+
Returns the status of a Zap transaction (pending, completed, failed).
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
### Token Utilities
|
|
183
|
+
|
|
184
|
+
#### `getAllTokens(chainId: number, source?: string, account?: string)`
|
|
185
|
+
|
|
186
|
+
- **Purpose:** Fetches all tokens for a chain, with optional price and account info.
|
|
187
|
+
- **Input:**
|
|
188
|
+
- `chainId`: number
|
|
189
|
+
- `source?`: string
|
|
190
|
+
- `account?`: string
|
|
191
|
+
- **Output:**
|
|
192
|
+
- Token list (with prices)
|
|
193
|
+
- **Description:**
|
|
194
|
+
Returns a list of tokens for the specified chain, with up-to-date prices.
|
|
195
|
+
|
|
196
|
+
#### `getTokenDetails(tokenAddress: string, chainId: number, account?: string, includeBalance?: boolean, includePrice?: boolean)`
|
|
197
|
+
|
|
198
|
+
- **Purpose:** Fetches details for a specific token.
|
|
199
|
+
- **Input:**
|
|
200
|
+
- `tokenAddress`: string
|
|
201
|
+
- `chainId`: number
|
|
202
|
+
- `account?`: string
|
|
203
|
+
- `includeBalance?`: boolean
|
|
204
|
+
- `includePrice?`: boolean
|
|
205
|
+
- **Output:**
|
|
206
|
+
- Token details object
|
|
207
|
+
- **Description:**
|
|
208
|
+
Returns metadata, balance, and/or price for a token.
|
|
209
|
+
|
|
210
|
+
#### `getTokenPrices(tokenAddresses: string[], chainId: number): Promise<Record<string, string | null>>`
|
|
211
|
+
|
|
212
|
+
- **Purpose:** Fetches prices for a list of tokens on a chain.
|
|
213
|
+
- **Input:**
|
|
214
|
+
- `tokenAddresses`: string[]
|
|
215
|
+
- `chainId`: number
|
|
216
|
+
- **Output:**
|
|
217
|
+
- Mapping of token address to price (as string or null)
|
|
218
|
+
- **Description:**
|
|
219
|
+
Returns the latest prices for the specified tokens.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### Chain Utilities
|
|
224
|
+
|
|
225
|
+
#### `getAllSupportedChains(): Promise<ChainData>`
|
|
226
|
+
|
|
227
|
+
- **Purpose:** Fetches all supported chains and their configuration.
|
|
228
|
+
- **Output:**
|
|
229
|
+
- `Promise<ChainData>`
|
|
230
|
+
- **Description:**
|
|
231
|
+
Returns a mapping of chain IDs to chain configuration objects.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
### Approval and Signature Utilities
|
|
236
|
+
|
|
237
|
+
#### `getAllowance({ chainId, sender, tokens, rpcUrls, service, mode })`
|
|
238
|
+
|
|
239
|
+
- **Purpose:** Checks token allowances for a sender with support for different approval modes.
|
|
240
|
+
- **Input:**
|
|
241
|
+
- `chainId`: number
|
|
242
|
+
- `sender`: HexString
|
|
243
|
+
- `tokens`: Array of `{ address: HexString; amount: bigint }`
|
|
244
|
+
- `rpcUrls?`: string[]
|
|
245
|
+
- `service`: AvailableDZapServices
|
|
246
|
+
- `mode?`: ApprovalMode (defaults to `ApprovalModes.AutoPermit`)
|
|
247
|
+
- **Output:**
|
|
248
|
+
- `{ status, code, data: { tokenAllowances, noOfApprovalsRequired, noOfSignaturesRequired } }`
|
|
249
|
+
- **Description:**
|
|
250
|
+
Returns the current allowance for each token and indicates how many approvals/signatures are needed.
|
|
251
|
+
|
|
252
|
+
#### `approve({ chainId, signer, sender, rpcUrls, tokens, service, mode, approvalTxnCallback })`
|
|
253
|
+
|
|
254
|
+
- **Purpose:** Approves tokens for spending based on the specified approval mode.
|
|
255
|
+
- **Input:**
|
|
256
|
+
- `chainId`: number
|
|
257
|
+
- `signer`: `Signer` or `WalletClient`
|
|
258
|
+
- `sender`: HexString
|
|
259
|
+
- `rpcUrls?`: string[]
|
|
260
|
+
- `tokens`: Array of `{ address: HexString; amount: bigint }`
|
|
261
|
+
- `service`: AvailableDZapServices
|
|
262
|
+
- `mode?`: ApprovalMode (defaults to `ApprovalModes.AutoPermit`)
|
|
263
|
+
- `approvalTxnCallback?`: callback for transaction status updates
|
|
264
|
+
- **Output:**
|
|
265
|
+
- Approval transaction result
|
|
266
|
+
- **Description:**
|
|
267
|
+
Sends approval transactions for the specified tokens. The spender is automatically determined based on the approval mode.
|
|
268
|
+
|
|
269
|
+
#### `sign({ chainId, sender, tokens, rpcUrls, service, signer, permitType, signatureCallback })`
|
|
270
|
+
|
|
271
|
+
- **Purpose:** Signs EIP-2612Permit/Permit2 data for gas-less token approvals.
|
|
272
|
+
- **Input:**
|
|
273
|
+
- `chainId`: number
|
|
274
|
+
- `sender`: HexString
|
|
275
|
+
- `tokens`: Array of `{ address: HexString; amount: string }`
|
|
276
|
+
- `service`: AvailableDZapServices
|
|
277
|
+
- `signer`: `Signer` or `WalletClient`
|
|
278
|
+
- `permitType?`: PermitMode (defaults to `PermitTypes.AutoPermit`)
|
|
279
|
+
- `rpcUrls?`: string[]
|
|
280
|
+
- `signatureCallback?`: Callback function for each signature result
|
|
281
|
+
- **Output:**
|
|
282
|
+
- `{ status, code, data }` with permit signatures populated
|
|
283
|
+
- **Description:**
|
|
284
|
+
Signs permit data for gas-less approvals. Automatically handles EIP2612 or Permit2 based on token support and permit type. The spender is automatically determined based on the permit type.
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Token Approval Mechanism
|
|
289
|
+
|
|
290
|
+
Before executing any transaction that spends ERC20 tokens (swap, bridge, zap, etc.), the DZap contract must be approved to access those tokens. The SDK provides multiple approval modes to handle different scenarios:
|
|
291
|
+
|
|
292
|
+
### Approval Modes
|
|
293
|
+
|
|
294
|
+
The SDK supports four approval modes via `ApprovalModes`:
|
|
295
|
+
|
|
296
|
+
#### 1. **Default Mode** (`ApprovalModes.Default`)
|
|
297
|
+
|
|
298
|
+
Standard ERC20 approval directly to the DZap contract.
|
|
299
|
+
|
|
300
|
+
- **How it works**: Traditional `approve()` call on the token contract
|
|
301
|
+
- **Gas**: Requires gas for the approval transaction
|
|
302
|
+
- **Spender**: DZap router/contract address
|
|
303
|
+
- **Use case**: Standard approval flow for all ERC20 tokens
|
|
304
|
+
|
|
305
|
+
#### 2. **Permit2 Mode** (`ApprovalModes.Permit2`)
|
|
306
|
+
|
|
307
|
+
Uses Uniswap's Permit2 for gas-less approvals.
|
|
308
|
+
|
|
309
|
+
- **How it works**: Two-step process - `approve` Permit2 contract once, then `sign` permits
|
|
310
|
+
- **Gas**: Initial approval to Permit2, then gas-less signatures
|
|
311
|
+
- **Spender**: Permit2 contract address
|
|
312
|
+
- **Use case**: Gas-efficient repeated transactions
|
|
313
|
+
|
|
314
|
+
#### 3. **EIP2612 Permit Mode** (`ApprovalModes.EIP2612Permit`)
|
|
315
|
+
|
|
316
|
+
Uses EIP2612 permit signatures directly to the DZap contract.
|
|
317
|
+
|
|
318
|
+
- **How it works**: Sign a permit message instead of sending approval transaction
|
|
319
|
+
- **Gas**: Gas-less (signature only)
|
|
320
|
+
- **Spender**: DZap router/contract address
|
|
321
|
+
- **Use case**: Tokens that support EIP2612 permits
|
|
322
|
+
|
|
323
|
+
#### 4. **Auto Permit Mode** (`ApprovalModes.AutoPermit`)
|
|
324
|
+
|
|
325
|
+
Automatically chooses between EIP2612 and Permit2 based on token support.
|
|
326
|
+
|
|
327
|
+
- **How it works**: Checks if token supports EIP2612, falls back to Permit2
|
|
328
|
+
- **Gas**: Gas-less if EIP2612 supported, otherwise Permit2 flow
|
|
329
|
+
- **Spender**: Automatically determined
|
|
330
|
+
- **Use case**: Best user experience with automatic optimization
|
|
331
|
+
|
|
332
|
+
### Recommended Flow
|
|
333
|
+
|
|
334
|
+
1. **Check Allowance**: Use `getAllowance()` to check if approval is needed
|
|
335
|
+
2. **Choose Mode**: Use `ApprovalModes.AutoPermit` for best user experience
|
|
336
|
+
3. **Approve if Needed**: Use `approve()` for on-chain approvals
|
|
337
|
+
4. **Sign if Preferred**: Use `sign()` for gas-less permit signatures
|
|
338
|
+
5. **Execute Transaction**: Pass permit data to transaction methods
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## Types
|
|
343
|
+
|
|
344
|
+
All input/output types are defined in the SDK's `src/types` directory. Refer to those files for detailed type definitions.
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## License
|
|
349
|
+
|
|
350
|
+
MIT
|
|
351
|
+
|
|
352
|
+
---
|
|
353
|
+
|
|
354
|
+
**For more details, refer to the source code and type definitions.**
|
|
355
|
+
If you have questions or need help, open an issue or contact the maintainers.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CancelToken } from 'axios';
|
|
2
|
+
import { ZapBuildTxnRequest, ZapQuoteRequest, ZapStatusRequest } from 'src/types/zap';
|
|
3
|
+
import { CalculatePointsRequest, TradeBuildTxnRequest, TradeQuotesRequest } from '../types';
|
|
4
|
+
export declare const fetchTradeQuotes: (request: TradeQuotesRequest) => Promise<any>;
|
|
5
|
+
export declare const fetchTradeBuildTxnData: (request: TradeBuildTxnRequest) => Promise<any>;
|
|
6
|
+
export declare const fetchZapBuildTxnData: (request: ZapBuildTxnRequest, cancelToken?: CancelToken) => Promise<any>;
|
|
7
|
+
export declare const fetchZapQuote: (request: ZapQuoteRequest, cancelToken?: CancelToken) => Promise<any>;
|
|
8
|
+
export declare const fetchZapTxnStatus: (request: ZapStatusRequest) => Promise<any>;
|
|
9
|
+
export declare const fetchAllSupportedChains: () => Promise<any>;
|
|
10
|
+
export declare const fetchAllTokens: (chainId: number, source?: string, account?: string) => Promise<any>;
|
|
11
|
+
export declare const fetchTokenDetails: (tokenAddress: string | string[], chainId: number, account?: string, includeBalance?: boolean, includePrice?: boolean) => Promise<any>;
|
|
12
|
+
export declare const fetchTokenPrice: (tokenAddresses: string[], chainId: number) => Promise<any>;
|
|
13
|
+
export declare const fetchStatus: ({ txHash, txIds, chainId }: {
|
|
14
|
+
txHash?: string;
|
|
15
|
+
txIds?: string;
|
|
16
|
+
chainId?: number;
|
|
17
|
+
}) => Promise<any>;
|
|
18
|
+
export declare const fetchCalculatedPoints: (request: CalculatePointsRequest) => Promise<any>;
|
|
19
|
+
export declare const fetchBalances: (chainId: number, account: string) => Promise<any>;
|