@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.
Files changed (79) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +21 -0
  3. package/README.md +355 -0
  4. package/dist/api/index.d.ts +19 -0
  5. package/dist/artifacts/ERC20Permit.d.ts +336 -0
  6. package/dist/artifacts/Permit2.d.ts +700 -0
  7. package/dist/artifacts/default/DZapCoreAbi.d.ts +2 -0
  8. package/dist/artifacts/default/DZapDcaAbi.d.ts +2 -0
  9. package/dist/artifacts/default/Permit2Abi.d.ts +70 -0
  10. package/dist/artifacts/default/erc20Abi.d.ts +165 -0
  11. package/dist/artifacts/default/index.d.ts +5 -0
  12. package/dist/artifacts/index.d.ts +2 -0
  13. package/dist/artifacts/staging/DZapCoreSwapAbi.d.ts +2 -0
  14. package/dist/artifacts/staging/index.d.ts +2 -0
  15. package/dist/axios/baseClient.d.ts +2 -0
  16. package/dist/axios/index.d.ts +8 -0
  17. package/dist/config.d.ts +16 -0
  18. package/dist/constants/address.d.ts +13 -0
  19. package/dist/constants/approval.d.ts +5 -0
  20. package/dist/constants/axios.d.ts +2 -0
  21. package/dist/constants/chains.d.ts +16 -0
  22. package/dist/constants/contract.d.ts +6 -0
  23. package/dist/constants/erc20.d.ts +22 -0
  24. package/dist/constants/httpMethods.d.ts +2 -0
  25. package/dist/constants/index.d.ts +43 -0
  26. package/dist/constants/permit.d.ts +5 -0
  27. package/dist/constants/permit2.d.ts +2 -0
  28. package/dist/constants/rpc.d.ts +2 -0
  29. package/dist/constants/urlConstants.d.ts +13 -0
  30. package/dist/dZapClient/index.d.ts +383 -0
  31. package/dist/enums/index.d.ts +36 -0
  32. package/dist/index.d.ts +15 -0
  33. package/dist/index.js +2 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/index.m.js +2 -0
  36. package/dist/index.m.js.map +1 -0
  37. package/dist/index.umd.js +2 -0
  38. package/dist/index.umd.js.map +1 -0
  39. package/dist/service/cache/cacheProvider.d.ts +10 -0
  40. package/dist/service/cache/constant.d.ts +2 -0
  41. package/dist/service/price/index.d.ts +16 -0
  42. package/dist/service/price/provider/coingecko/config.d.ts +6 -0
  43. package/dist/service/price/provider/coingecko/index.d.ts +9 -0
  44. package/dist/service/price/provider/defiLlama/config.d.ts +3 -0
  45. package/dist/service/price/provider/defiLlama/index.d.ts +9 -0
  46. package/dist/service/price/provider/defiLlama/types.d.ts +11 -0
  47. package/dist/service/price/provider/dzap/index.d.ts +6 -0
  48. package/dist/service/price/types/IPriceProvider.d.ts +14 -0
  49. package/dist/transactionHandlers/generic.d.ts +24 -0
  50. package/dist/transactionHandlers/permit.d.ts +58 -0
  51. package/dist/transactionHandlers/trade.d.ts +11 -0
  52. package/dist/transactionHandlers/zap.d.ts +37 -0
  53. package/dist/types/axiosClient.d.ts +6 -0
  54. package/dist/types/btc.d.ts +45 -0
  55. package/dist/types/chains.d.ts +2 -0
  56. package/dist/types/contract.d.ts +14 -0
  57. package/dist/types/eip-2612.d.ts +6 -0
  58. package/dist/types/index.d.ts +317 -0
  59. package/dist/types/zap/index.d.ts +65 -0
  60. package/dist/types/zap/path.d.ts +36 -0
  61. package/dist/types/zap/step.d.ts +15 -0
  62. package/dist/utils/amount.d.ts +82 -0
  63. package/dist/utils/axios.d.ts +13 -0
  64. package/dist/utils/chains.d.ts +2 -0
  65. package/dist/utils/date.d.ts +1 -0
  66. package/dist/utils/erc20.d.ts +61 -0
  67. package/dist/utils/errors.d.ts +16 -0
  68. package/dist/utils/index.d.ts +3940 -0
  69. package/dist/utils/multicall.d.ts +12 -0
  70. package/dist/utils/permit/permit2Methods.d.ts +32 -0
  71. package/dist/utils/permit/permitMethods.d.ts +29 -0
  72. package/dist/utils/signTypedData.d.ts +11 -0
  73. package/dist/utils/tokens.d.ts +7 -0
  74. package/dist/utils/updateQuotes.d.ts +3 -0
  75. package/dist/zap/constants/index.d.ts +2 -0
  76. package/dist/zap/constants/path.d.ts +8 -0
  77. package/dist/zap/constants/step.d.ts +3 -0
  78. package/dist/zap/constants/urls.d.ts +3 -0
  79. package/package.json +115 -0
@@ -0,0 +1,383 @@
1
+ import { Signer, Wallet } from 'ethers';
2
+ import { StatusCodes, TxnStatus } from 'src/enums';
3
+ import { ApprovalMode, AvailableDZapServices, CalculatePointsRequest, ChainData, ExecuteTxnData, HexString, OtherAvailableAbis, PermitMode, TokenInfo, TokenResponse, TradeBuildTxnRequest, TradeBuildTxnResponse, TradeQuotesRequest, TradeQuotesResponse, TradeStatusResponse } from 'src/types';
4
+ import { ZapBuildTxnRequest, ZapBuildTxnResponse, ZapQuoteRequest, ZapQuoteResponse, ZapStatusRequest, ZapStatusResponse } from 'src/types/zap';
5
+ import { ZapTransactionStep } from 'src/types/zap/step';
6
+ import { TransactionReceipt, WalletClient } from 'viem';
7
+ declare class DZapClient {
8
+ private static instance;
9
+ private cancelTokenSource;
10
+ private static chainConfig;
11
+ private priceService;
12
+ rpcUrlsByChainId: Record<number, string[]>;
13
+ private constructor();
14
+ static getInstance(rpcUrlsByChainId?: Record<number, string[]>): DZapClient;
15
+ static getChainConfig(): Promise<ChainData>;
16
+ static getDZapAbi(service: AvailableDZapServices): import("viem").Abi;
17
+ static getOtherAbi: (name: OtherAvailableAbis) => ({
18
+ inputs: {
19
+ internalType: string;
20
+ name: string;
21
+ type: string;
22
+ }[];
23
+ name: string;
24
+ type: string;
25
+ anonymous?: undefined;
26
+ outputs?: undefined;
27
+ stateMutability?: undefined;
28
+ } | {
29
+ anonymous: boolean;
30
+ inputs: {
31
+ indexed: boolean;
32
+ internalType: string;
33
+ name: string;
34
+ type: string;
35
+ }[];
36
+ name: string;
37
+ type: string;
38
+ outputs?: undefined;
39
+ stateMutability?: undefined;
40
+ } | {
41
+ inputs: {
42
+ internalType: string;
43
+ name: string;
44
+ type: string;
45
+ }[];
46
+ name: string;
47
+ outputs: {
48
+ internalType: string;
49
+ name: string;
50
+ type: string;
51
+ }[];
52
+ stateMutability: string;
53
+ type: string;
54
+ anonymous?: undefined;
55
+ } | {
56
+ inputs: ({
57
+ internalType: string;
58
+ name: string;
59
+ type: string;
60
+ components?: undefined;
61
+ } | {
62
+ components: ({
63
+ components: {
64
+ internalType: string;
65
+ name: string;
66
+ type: string;
67
+ }[];
68
+ internalType: string;
69
+ name: string;
70
+ type: string;
71
+ } | {
72
+ internalType: string;
73
+ name: string;
74
+ type: string;
75
+ components?: undefined;
76
+ })[];
77
+ internalType: string;
78
+ name: string;
79
+ type: string;
80
+ })[];
81
+ name: string;
82
+ outputs: never[];
83
+ stateMutability: string;
84
+ type: string;
85
+ anonymous?: undefined;
86
+ })[] | readonly [{
87
+ readonly constant: true;
88
+ readonly inputs: readonly [];
89
+ readonly name: "name";
90
+ readonly outputs: readonly [{
91
+ readonly name: "";
92
+ readonly type: "string";
93
+ }];
94
+ readonly payable: false;
95
+ readonly stateMutability: "view";
96
+ readonly type: "function";
97
+ }, {
98
+ readonly constant: false;
99
+ readonly inputs: readonly [{
100
+ readonly name: "_spender";
101
+ readonly type: "address";
102
+ }, {
103
+ readonly name: "_value";
104
+ readonly type: "uint256";
105
+ }];
106
+ readonly name: "approve";
107
+ readonly outputs: readonly [];
108
+ readonly payable: false;
109
+ readonly stateMutability: "nonpayable";
110
+ readonly type: "function";
111
+ }, {
112
+ readonly constant: true;
113
+ readonly inputs: readonly [];
114
+ readonly name: "totalSupply";
115
+ readonly outputs: readonly [{
116
+ readonly name: "";
117
+ readonly type: "uint256";
118
+ }];
119
+ readonly payable: false;
120
+ readonly stateMutability: "view";
121
+ readonly type: "function";
122
+ }, {
123
+ readonly constant: false;
124
+ readonly inputs: readonly [{
125
+ readonly name: "_from";
126
+ readonly type: "address";
127
+ }, {
128
+ readonly name: "_to";
129
+ readonly type: "address";
130
+ }, {
131
+ readonly name: "_value";
132
+ readonly type: "uint256";
133
+ }];
134
+ readonly name: "transferFrom";
135
+ readonly outputs: readonly [{
136
+ readonly name: "";
137
+ readonly type: "bool";
138
+ }];
139
+ readonly payable: false;
140
+ readonly stateMutability: "nonpayable";
141
+ readonly type: "function";
142
+ }, {
143
+ readonly constant: true;
144
+ readonly inputs: readonly [];
145
+ readonly name: "decimals";
146
+ readonly outputs: readonly [{
147
+ readonly name: "";
148
+ readonly type: "uint8";
149
+ }];
150
+ readonly payable: false;
151
+ readonly stateMutability: "view";
152
+ readonly type: "function";
153
+ }, {
154
+ readonly constant: true;
155
+ readonly inputs: readonly [{
156
+ readonly name: "_owner";
157
+ readonly type: "address";
158
+ }];
159
+ readonly name: "balanceOf";
160
+ readonly outputs: readonly [{
161
+ readonly name: "balance";
162
+ readonly type: "uint256";
163
+ }];
164
+ readonly payable: false;
165
+ readonly stateMutability: "view";
166
+ readonly type: "function";
167
+ }, {
168
+ readonly constant: true;
169
+ readonly inputs: readonly [];
170
+ readonly name: "symbol";
171
+ readonly outputs: readonly [{
172
+ readonly name: "";
173
+ readonly type: "string";
174
+ }];
175
+ readonly payable: false;
176
+ readonly stateMutability: "view";
177
+ readonly type: "function";
178
+ }, {
179
+ readonly constant: false;
180
+ readonly inputs: readonly [{
181
+ readonly name: "_to";
182
+ readonly type: "address";
183
+ }, {
184
+ readonly name: "_value";
185
+ readonly type: "uint256";
186
+ }];
187
+ readonly name: "transfer";
188
+ readonly outputs: readonly [{
189
+ readonly name: "";
190
+ readonly type: "bool";
191
+ }];
192
+ readonly payable: false;
193
+ readonly stateMutability: "nonpayable";
194
+ readonly type: "function";
195
+ }, {
196
+ readonly constant: true;
197
+ readonly inputs: readonly [{
198
+ readonly name: "_owner";
199
+ readonly type: "address";
200
+ }, {
201
+ readonly name: "_spender";
202
+ readonly type: "address";
203
+ }];
204
+ readonly name: "allowance";
205
+ readonly outputs: readonly [{
206
+ readonly name: "";
207
+ readonly type: "uint256";
208
+ }];
209
+ readonly payable: false;
210
+ readonly stateMutability: "view";
211
+ readonly type: "function";
212
+ }, {
213
+ readonly payable: true;
214
+ readonly stateMutability: "payable";
215
+ readonly type: "fallback";
216
+ }, {
217
+ readonly anonymous: false;
218
+ readonly inputs: readonly [{
219
+ readonly indexed: true;
220
+ readonly name: "owner";
221
+ readonly type: "address";
222
+ }, {
223
+ readonly indexed: true;
224
+ readonly name: "spender";
225
+ readonly type: "address";
226
+ }, {
227
+ readonly indexed: false;
228
+ readonly name: "value";
229
+ readonly type: "uint256";
230
+ }];
231
+ readonly name: "Approval";
232
+ readonly type: "event";
233
+ }, {
234
+ readonly anonymous: false;
235
+ readonly inputs: readonly [{
236
+ readonly indexed: true;
237
+ readonly name: "from";
238
+ readonly type: "address";
239
+ }, {
240
+ readonly indexed: true;
241
+ readonly name: "to";
242
+ readonly type: "address";
243
+ }, {
244
+ readonly indexed: false;
245
+ readonly name: "value";
246
+ readonly type: "uint256";
247
+ }];
248
+ readonly name: "Transfer";
249
+ readonly type: "event";
250
+ }];
251
+ getTradeQuotes(request: TradeQuotesRequest): Promise<TradeQuotesResponse>;
252
+ buildTradeTxn(request: TradeBuildTxnRequest): Promise<TradeBuildTxnResponse>;
253
+ getTradeTxnStatus({ txHash, txIds, chainId, }: {
254
+ txHash?: string;
255
+ txIds?: string;
256
+ chainId?: number;
257
+ }): Promise<TradeStatusResponse | Record<string, TradeStatusResponse>>;
258
+ getAllSupportedChains(): Promise<ChainData>;
259
+ getAllTokens(chainId: number, source?: string, account?: string): Promise<any>;
260
+ getTokenDetails(tokenAddress: string, chainId: number, account?: string, includeBalance?: boolean, includePrice?: boolean): Promise<TokenInfo>;
261
+ getTokensDetails(tokenAddresses: string[], chainId: number, account?: string, includeBalance?: boolean, includePrice?: boolean): Promise<Record<string, TokenInfo>>;
262
+ getTokenPrices(tokenAddresses: string[], chainId: number): Promise<Record<string, string | null>>;
263
+ trade({ request, signer, txnData, }: {
264
+ request: TradeBuildTxnRequest;
265
+ signer: Signer | WalletClient;
266
+ txnData?: TradeBuildTxnResponse;
267
+ }): Promise<import("src/types").DZapTransactionResponse>;
268
+ sendTransaction({ signer, txnData }: {
269
+ chainId: number;
270
+ signer: Signer | WalletClient;
271
+ txnData: ExecuteTxnData;
272
+ }): Promise<{
273
+ status: TxnStatus;
274
+ error: any;
275
+ errorMsg: any;
276
+ code: StatusCodes;
277
+ } | {
278
+ status: TxnStatus;
279
+ code: StatusCodes;
280
+ txnHash: HexString;
281
+ }>;
282
+ decodeTxnData({ data, service, chainId }: {
283
+ data: TransactionReceipt;
284
+ service: AvailableDZapServices;
285
+ chainId: number;
286
+ }): Promise<{
287
+ swapFailPairs: string[];
288
+ swapInfo: import("src/types").SwapInfo | import("src/types").SwapInfo[];
289
+ }>;
290
+ calculatePoints(request: CalculatePointsRequest): Promise<{
291
+ points: number;
292
+ }>;
293
+ getDZapContractAddress({ chainId, service }: {
294
+ chainId: number;
295
+ service: AvailableDZapServices;
296
+ }): Promise<string>;
297
+ getAllowance({ chainId, sender, tokens, service, rpcUrls, spender, mode, }: {
298
+ chainId: number;
299
+ sender: HexString;
300
+ tokens: {
301
+ address: HexString;
302
+ amount: bigint;
303
+ }[];
304
+ service: AvailableDZapServices;
305
+ rpcUrls?: string[];
306
+ spender?: HexString;
307
+ mode?: ApprovalMode;
308
+ }): Promise<{
309
+ status: TxnStatus;
310
+ code: StatusCodes;
311
+ data: {
312
+ [key: string]: {
313
+ allowance: bigint;
314
+ approvalNeeded: boolean;
315
+ signatureNeeded: boolean;
316
+ };
317
+ };
318
+ }>;
319
+ approve({ chainId, signer, tokens, approvalTxnCallback, service, mode, rpcUrls, spender, }: {
320
+ chainId: number;
321
+ signer: WalletClient | Signer;
322
+ tokens: {
323
+ address: HexString;
324
+ amount: bigint;
325
+ }[];
326
+ approvalTxnCallback?: ({ txnDetails, address, }: {
327
+ txnDetails: {
328
+ txnHash: string;
329
+ code: StatusCodes;
330
+ status: TxnStatus;
331
+ };
332
+ address: HexString;
333
+ }) => Promise<TxnStatus | void>;
334
+ service: AvailableDZapServices;
335
+ spender?: HexString;
336
+ rpcUrls?: string[];
337
+ mode?: ApprovalMode;
338
+ }): Promise<{
339
+ status: TxnStatus;
340
+ code: StatusCodes;
341
+ }>;
342
+ sign({ chainId, sender, tokens, service, spender, rpcUrls, signer, permitType, signatureCallback, }: {
343
+ chainId: number;
344
+ sender: HexString;
345
+ tokens: {
346
+ address: HexString;
347
+ amount: string;
348
+ }[];
349
+ service: AvailableDZapServices;
350
+ signer: WalletClient | Wallet;
351
+ spender?: HexString;
352
+ rpcUrls?: string[];
353
+ permitType?: PermitMode;
354
+ signatureCallback?: ({ permitData, srcToken, amount, permitType, }: {
355
+ permitData: HexString;
356
+ srcToken: string;
357
+ amount: bigint;
358
+ permitType: PermitMode;
359
+ }) => Promise<void>;
360
+ }): Promise<{
361
+ status: TxnStatus;
362
+ tokens: {
363
+ address: HexString;
364
+ permitData?: HexString;
365
+ amount: string;
366
+ }[];
367
+ code: StatusCodes;
368
+ }>;
369
+ zap({ request, steps, signer }: {
370
+ request: ZapBuildTxnRequest;
371
+ signer: WalletClient | Signer;
372
+ steps?: ZapTransactionStep[];
373
+ }): Promise<import("src/types").DZapTransactionResponse | {
374
+ status: TxnStatus.success;
375
+ code: StatusCodes | number;
376
+ txnHash: HexString;
377
+ }>;
378
+ buildZapTxn(request: ZapBuildTxnRequest): Promise<ZapBuildTxnResponse>;
379
+ getZapQuote(request: ZapQuoteRequest): Promise<ZapQuoteResponse>;
380
+ getZapTxnStatus(request: ZapStatusRequest): Promise<ZapStatusResponse>;
381
+ getBalances(chainId: number, account: string): Promise<Record<string, TokenResponse>>;
382
+ }
383
+ export default DZapClient;
@@ -0,0 +1,36 @@
1
+ export declare enum AppEnv {
2
+ 'production' = "production",
3
+ 'development' = "development"
4
+ }
5
+ export declare enum ZapPermitType {
6
+ PERMIT = 0,
7
+ PERMIT2 = 1
8
+ }
9
+ export declare enum PermitType {
10
+ PERMIT = 0,
11
+ PERMIT2_TRANSFER_FROM = 1,
12
+ PERMIT2_APPROVE = 2
13
+ }
14
+ export declare enum TxnStatus {
15
+ mining = "mining",
16
+ success = "success",
17
+ rejected = "rejected",
18
+ error = "error",
19
+ reverted = "reverted",
20
+ pendingWalletConfirmation = "pendingWalletConfirmation",
21
+ partialSuccess = "partialSuccess"
22
+ }
23
+ export declare enum Versions {
24
+ V1 = "v1",
25
+ V1_2 = "v1.2",
26
+ V2 = "v2"
27
+ }
28
+ export declare enum StatusCodes {
29
+ UserRejectedRequest = 4001,
30
+ Success = 200,
31
+ FunctionNotFound = 32771,
32
+ Error = 500,
33
+ WalletRPCFailure = 429,
34
+ SimulationFailure = 417,
35
+ ContractExecutionError = -500
36
+ }
@@ -0,0 +1,15 @@
1
+ import { OtherAbis, QuoteFilters, Services, STATUS } from './constants';
2
+ import { SignatureExpiryInSecs } from './constants/permit2';
3
+ import { PermitType, StatusCodes, TxnStatus } from './enums';
4
+ import { ApiRpcResponse, ApprovalMode, Chain, ChainData, contractErrorActions, ContractErrorResponse, DZapTransactionResponse, ExecuteTxnData, Fee, FeeDetails, HexString, PermitMode, ProviderDetails, QuoteFilter, SwapInfo, Token, TokenInfo, TokenResponse, TradeBuildTxnRequest, TradeBuildTxnRequestData, TradeBuildTxnResponse, TradePath, TradeQuotesRequest, TradeQuotesRequestData, TradeQuotesResponse, TradeStatusResponse, TradeStep } from './types';
5
+ import { PsbtInput, PsbtOutput } from './types/btc';
6
+ import { formatToken, getTokensPairKey } from './utils';
7
+ import { ApprovalModes } from './constants/approval';
8
+ import { erc20Functions } from './constants/erc20';
9
+ import { PermitTypes } from './constants/permit';
10
+ import DZapClient from './dZapClient';
11
+ import { checkEIP2612PermitSupport } from './utils/permit/permitMethods';
12
+ import { ZapStatusResponse } from './types/zap';
13
+ export * from './types/zap';
14
+ export * from './zap/constants';
15
+ export { ApiRpcResponse, ApprovalMode, ApprovalModes, Chain, ChainData, checkEIP2612PermitSupport, contractErrorActions, ContractErrorResponse, DZapClient, DZapTransactionResponse, erc20Functions, ExecuteTxnData, Fee, FeeDetails, formatToken, getTokensPairKey, HexString, OtherAbis, PermitMode, PermitType, PermitTypes, ProviderDetails, PsbtInput, PsbtOutput, QuoteFilter, QuoteFilters, Services, SignatureExpiryInSecs, STATUS, StatusCodes, SwapInfo, Token, TokenInfo, TokenResponse, TradeBuildTxnRequest, TradeBuildTxnRequestData, TradeBuildTxnResponse, TradePath, TradeQuotesRequest, TradeQuotesRequestData, TradeQuotesResponse, TradeStep, TxnStatus, TradeStatusResponse, ZapStatusResponse, };