@swapkit/helpers 1.2.3 → 1.2.4

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.
@@ -1,10 +1,149 @@
1
1
  import { z } from "zod";
2
2
 
3
+ export enum ErrorCode {
4
+ unknownError = "unknownError",
5
+ test_error = "test_error",
6
+ providerDetailsError = "providerDetailsError",
7
+ blockHeaderNotFound = "blockHeaderNotFound",
8
+ blockHashNotFoundAtHeight = "blockHashNotFoundAtHeight",
9
+ blockHashNotFoundAtHash = "blockHashNotFoundAtHash",
10
+ txHashMissing = "txHashMissing",
11
+ assetValueMissingInfo = "assetValueMissingInfo",
12
+ invalidAsset = "invalidAsset",
13
+ blockIsRequired = "blockIsRequired",
14
+ currentBlockHeaderNotFound = "currentBlockHeaderNotFound",
15
+ failedToRetrieveBalance = "failedToRetrieveBalance",
16
+ failedToRetrieveBlock = "failedToRetrieveBlock",
17
+ failedToRetrieveFees = "failedToRetrieveFees",
18
+ notImplementedBCH = "notImplementedBCH",
19
+ notImplementedDoge = "notImplementedDoge",
20
+ noPoolsFound = "noPoolsFound",
21
+ noVaultsFound = "noVaultsFound",
22
+ noTxFound = "noTxFound",
23
+ noInputCoinFound = "noInputCoinFound",
24
+ noBlockDataFound = "noBlockDataFound",
25
+ multipleCosmosMessages = "multipleCosmosMessages",
26
+ heightOrHashNotProvided = "heightOrHashNotProvided",
27
+ unknownDenom = "unknownDenom",
28
+ invalidBlockHeight = "invalidBlockHeight",
29
+ timestampExtrinsicNoArgumentsForBlock = "timestampExtrinsicNoArgumentsForBlock",
30
+ timestampExtrinsicNoTimestampForBlock = "timestampExtrinsicNoTimestampForBlock",
31
+ noTimestampExtrinsicForHash = "noTimestampExtrinsicForHash",
32
+ timestampExtrinsicNoArgumentsForHash = "timestampExtrinsicNoArgumentsForHash",
33
+ txMemoUndefined = "txMemoUndefined",
34
+ txMemoIncorrect = "txMemoIncorrect",
35
+ txTypeNotFound = "txTypeNotFound",
36
+ txNoMessage = "txNoMessage",
37
+ txNotFound = "txNotFound",
38
+ txReceiptNotFound = "txReceiptNotFound",
39
+ txParsingError = "txParsingError",
40
+ blockNotFound = "blockNotFound",
41
+ balanceNotFound = "balanceNotFound",
42
+ configError = "configError",
43
+ noQuoteResponse = "noQuoteResponse",
44
+ noPoolAssetsFound = "noPoolAssetsFound",
45
+ noThorchainPools = "noThorchainPools",
46
+ noMayachainPools = "noMayachainPools",
47
+ invalidAffiliateFee = "invalidAffiliateFee",
48
+ invalidBuyAssetAddress = "invalidBuyAssetAddress",
49
+ invalidSellAssetAddress = "invalidSellAssetAddress",
50
+ invalidSourceAddress = "invalidSourceAddress",
51
+ invalidDestinationAddress = "invalidDestinationAddress",
52
+ sourceAddressIsSmartContract = "sourceAddressIsSmartContract",
53
+ destinationAddressIsSmartContract = "destinationAddressIsSmartContract",
54
+ invalidChainId = "invalidChainId",
55
+ unsupportedChainId = "unsupportedChainId",
56
+ unsupportedEVMChainId = "unsupportedEVMChainId",
57
+ noWhitelistTokens = "noWhitelistTokens",
58
+ failedFetchGasPrice = "failedFetchGasPrice",
59
+ failedToCreateDepositChannel = "failedToCreateDepositChannel",
60
+ noProviderDetailsFound = "noProviderDetailsFound",
61
+ noTokenListsFound = "noTokenListsFound",
62
+ tokenNotFound = "tokenNotFound",
63
+ tokenPriceNotFound = "tokenPriceNotFound",
64
+ swapAmountTooSmall = "swapAmountTooSmall",
65
+ legsArrayIsEmpty = "legsArrayIsEmpty",
66
+ failedToFetchQuoteForLeg = "failedToFetchQuoteForLeg",
67
+ noBlockHeaderFound = "noBlockHeaderFound",
68
+ failedToSimulateSwap = "failedToSimulateSwap",
69
+ addressScreeningFailed = "addressScreeningFailed",
70
+ noLiquidtyProvidersFound = "noLiquidtyProvidersFound",
71
+ noSaversFound = "noSaversFound",
72
+ noInboundAddressesFound = "noInboundAddressesFound",
73
+ noInboundAddressFoundForChain = "noInboundAddressFoundForChain",
74
+ noLastBlocksFound = "noLastBlocksFound",
75
+ noVersionFound = "noVersionFound",
76
+ noConstantsFound = "noConstantsFound",
77
+ noMimirsFound = "noMimirsFound",
78
+ noRoutesFound = "noRoutesFound",
79
+ quoteNotFound = "quoteNotFound",
80
+ ledgerSignFailed = "ledgerSignFailed",
81
+ ledgerFetchSwapFailed = "ledgerFetchSwapFailed",
82
+ failedToFetchTx = "failedToFetchTx",
83
+ failedBuildTransactionDetails = "failedBuildTransactionDetails",
84
+ noLegsForRoute = "noLegsForRoute",
85
+ noRouterAddressFound = "noRouterAddressFound",
86
+ noAggregatorAddressFound = "noAggregatorAddressFound",
87
+ noContractInstanceFound = "noContractInstanceFound",
88
+ noContractAddressFound = "noContractAddressFound",
89
+ invalidAffiliate = "invalidAffiliate",
90
+ providerNotfound = "No provider found",
91
+ noRecordFound = "No Record found",
92
+ slippageTooLow = "Slippage too low",
93
+ tradingHalted = "tradingHalted",
94
+ noWrappedGasAsset = "noWrappedGasAsset",
95
+ aggregatorAddressNotFound = "aggregatorAddressNotFound",
96
+ routerAddressNotFound = "routerAddressNotFound",
97
+ dummyAddressNotFound = "dummyAddressNotFound",
98
+ trackerError = "trackerError",
99
+ noOhlcvDataFound = "noOhlcvDataFound",
100
+ noTradingPairs = "noTradingPairs",
101
+ noLoanPositionFound = "noLoanPositionFound",
102
+ noLendingAvailability = "noLendingAvailability",
103
+ lendingRepayTooSmall = "lendingRepayTooSmall",
104
+ missingState = "missingState",
105
+ ledgerSwapNotFound = "ledgerSwapNotFound",
106
+ ledgerSwapNotReadyForTracking = "ledgerSwapNotReadyForTracking",
107
+ errorEstimatingGas = "errorEstimatingGas",
108
+ apiKeyInvalid = "apiKeyInvalid",
109
+ apiKeyFailedToUpdate = "apiKeyFailedToUpdate",
110
+ apiKeyExpired = "apiKeyExpired",
111
+ unauthorized = "unauthorized",
112
+ failedToCreateMemo = "failedToCreateMemo",
113
+ radixIncorrectInstructions = "radixIncorrectInstructions",
114
+ invalidAddressForChain = "invalidAddressForChain",
115
+ }
116
+
3
117
  export enum WarningCodeEnum {
4
118
  highSlippage = "highSlippage",
5
119
  highPriceImpact = "highPriceImpact",
6
120
  }
7
121
 
122
+ export const EVMTransactionSchema = z.object({
123
+ to: z.string({
124
+ description: "Address of the recipient",
125
+ }),
126
+ from: z.string({
127
+ description: "Address of the sender",
128
+ }),
129
+ gas: z
130
+ .number({
131
+ description: "Gas limit",
132
+ })
133
+ .optional(),
134
+ gasPrice: z
135
+ .string({
136
+ description: "Gas price",
137
+ })
138
+ .optional(),
139
+ value: z.string({
140
+ description: "Value to send",
141
+ }),
142
+ data: z.string({
143
+ description: "Data to send",
144
+ }),
145
+ });
146
+
8
147
  export const EVMTransactionDetailsParamsSchema = z.array(
9
148
  z.union([
10
149
  z.string(),
@@ -182,75 +321,35 @@ export const RouteQuoteWarningSchema = z.array(
182
321
  }),
183
322
  );
184
323
 
185
- export const RouteQuoteLegSchema = z.object({
324
+ export type EVMTransaction = z.infer<typeof EVMTransactionSchema>;
325
+
326
+ const QuoteResponseRouteLegItemDev = z.object({
327
+ provider: z.nativeEnum(ProviderName),
186
328
  sellAsset: z.string({
187
329
  description: "Asset to sell",
188
330
  }),
331
+ sellAmount: z.string({
332
+ description: "Sell amount",
333
+ }),
189
334
  buyAsset: z.string({
190
335
  description: "Asset to buy",
191
336
  }),
192
- provider: z.nativeEnum(ProviderName),
193
337
  buyAmount: z.string({
194
- description: "Amount of asset to buy",
338
+ description: "Buy amount",
195
339
  }),
196
340
  buyAmountMaxSlippage: z.string({
197
- description: "Amount of asset to buy",
198
- }),
199
- sellAmount: z.string({
200
- description: "Amount of asset to sell",
201
- }),
202
- sourceAddress: z.string({
203
- description: "Source address",
204
- }),
205
- destinationAddress: z.string({
206
- description: "Destination address",
207
- }),
208
- slippageBps: z.number({
209
- description: "Slippage in bps",
341
+ description: "Buy amount max slippage",
210
342
  }),
211
- targetAddress: z.optional(
212
- z.string({
213
- description: "Target address for contract call or transfer address",
214
- }),
215
- ),
216
- inboundAddress: z.optional(
217
- z.string({
218
- description: "Inbound address",
219
- }),
220
- ),
221
- routerAddress: z.optional(
222
- z.string({
223
- description: "Inbound address",
224
- }),
225
- ),
226
- contractMethod: z.optional(
227
- z.string({
228
- description: "Contract method",
229
- }),
230
- ),
231
- fees: z.optional(FeesSchema),
232
- estimatedTime: z.optional(EstimatedTimeSchema),
233
- memo: z.optional(
234
- z.string({
235
- description: "Memo",
236
- }),
237
- ),
238
- expiration: z.optional(
239
- z.string({
240
- description: "Expiration",
241
- }),
242
- ),
343
+ fees: z.optional(FeesSchema), // TODO remove optionality
243
344
  });
244
345
 
245
- export type RouteQuoteLeg = z.infer<typeof RouteQuoteLegSchema>;
246
-
247
- export const RouteQuoteSchema = z.object({
346
+ const QuoteResponseRouteItemDev = z.object({
248
347
  providers: z.array(z.nativeEnum(ProviderName)),
249
348
  sellAsset: z.string({
250
349
  description: "Asset to sell",
251
350
  }),
252
351
  sellAmount: z.string({
253
- description: "sell amount",
352
+ description: "Sell amount",
254
353
  }),
255
354
  buyAsset: z.string({
256
355
  description: "Asset to buy",
@@ -272,16 +371,6 @@ export const RouteQuoteSchema = z.object({
272
371
  description: "Target address",
273
372
  }),
274
373
  ),
275
- routerAddress: z.optional(
276
- z.string({
277
- description: "Router address",
278
- }),
279
- ),
280
- inboundAddress: z.optional(
281
- z.string({
282
- description: "Inbound address",
283
- }),
284
- ),
285
374
  expiration: z.optional(
286
375
  z.string({
287
376
  description: "Expiration",
@@ -292,20 +381,33 @@ export const RouteQuoteSchema = z.object({
292
381
  description: "Memo",
293
382
  }),
294
383
  ),
295
- evmTransactionDetails: z.optional(EVMTransactionDetailsSchema),
296
- routePathArray: z.optional(z.array(z.string())),
297
- estimatedTime: z.optional(EstimatedTimeSchema),
384
+ fees: FeesSchema,
385
+ tx: z.optional(EVMTransactionSchema),
386
+ transaction: z.optional(z.unknown()), // Can take many forms depending on the chains
387
+ estimatedTime: z.optional(EstimatedTimeSchema), // TODO remove optionality
298
388
  totalSlippageBps: z.number({
299
389
  description: "Total slippage in bps",
300
390
  }),
301
- legs: z.array(RouteQuoteLegSchema),
302
- // TODO use enum
303
- errorCode: z.optional(z.string()),
391
+ legs: z.array(QuoteResponseRouteLegItemDev),
304
392
  warnings: RouteQuoteWarningSchema,
305
393
  meta: RouteQuoteMetadataSchema,
306
394
  });
307
395
 
308
- export type RouteQuote = z.infer<typeof RouteQuoteSchema>;
396
+ export const QuoteResponseSchemaDev = z.object({
397
+ quoteId: z.string({
398
+ description: "Quote ID",
399
+ }),
400
+ routes: z.array(QuoteResponseRouteItemDev),
401
+ error: z.optional(
402
+ z.string({
403
+ description: "Error message",
404
+ }),
405
+ ),
406
+ });
407
+
408
+ export type QuoteResponseDev = z.infer<typeof QuoteResponseSchemaDev>;
409
+ export type QuoteResponseRouteDev = z.infer<typeof QuoteResponseRouteItemDev>;
410
+ export type QuoteResponseRouteLegDev = z.infer<typeof QuoteResponseRouteLegItemDev>;
309
411
 
310
412
  const QuoteResponseRouteLegItem = z.object({
311
413
  provider: z.nativeEnum(ProviderName),
@@ -333,7 +435,7 @@ const QuoteResponseRouteItem = z.object({
333
435
  description: "Asset to sell",
334
436
  }),
335
437
  sellAmount: z.string({
336
- description: "sell amount",
438
+ description: "Sell amount",
337
439
  }),
338
440
  buyAsset: z.string({
339
441
  description: "Asset to buy",
@@ -366,6 +468,7 @@ const QuoteResponseRouteItem = z.object({
366
468
  }),
367
469
  ),
368
470
  evmTransactionDetails: z.optional(EVMTransactionDetailsSchema),
471
+ transaction: z.optional(z.unknown()), // Can take many forms depending on the chains
369
472
  estimatedTime: z.optional(EstimatedTimeSchema), // TODO remove optionality
370
473
  totalSlippageBps: z.number({
371
474
  description: "Total slippage in bps",
package/src/types/sdk.ts CHANGED
@@ -4,7 +4,7 @@ import { z } from "zod";
4
4
 
5
5
  import type { AssetValue } from "../modules/assetValue";
6
6
  import type { Chain, CosmosChain, UTXOChain } from "./chains";
7
- import type { QuoteResponseRoute } from "./quotes";
7
+ import { ProviderName, type QuoteResponseRoute } from "./quotes";
8
8
 
9
9
  type CovalentChains =
10
10
  | Chain.BinanceSmartChain
@@ -84,9 +84,19 @@ export const QuoteRequestSchema = z
84
84
  }),
85
85
  providers: z.optional(
86
86
  z.array(
87
- z.string({
88
- description: "List of providers to use",
89
- }),
87
+ z
88
+ .string({
89
+ description: "List of providers to use",
90
+ })
91
+ .refine(
92
+ (provider) => {
93
+ return ProviderName[provider as ProviderName] !== undefined;
94
+ },
95
+ {
96
+ message: "Invalid provider",
97
+ path: ["providers"],
98
+ },
99
+ ),
90
100
  ),
91
101
  ),
92
102
  sourceAddress: z.optional(
@@ -136,6 +146,11 @@ export const QuoteRequestSchema = z
136
146
  description: "Disable security checks",
137
147
  }),
138
148
  ),
149
+ includeTx: z.optional(
150
+ z.boolean({
151
+ description: "Set to true to include an transaction object (EVM only)",
152
+ }),
153
+ ),
139
154
  })
140
155
  .refine((data) => data.sellAsset !== data.buyAsset, {
141
156
  message: "Must be different",