@swapkit/helpers 1.2.2 → 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.
- package/dist/index.js +3 -3
- package/dist/index.js.map +5 -5
- package/package.json +7 -7
- package/src/modules/requestClient.ts +6 -4
- package/src/types/quotes.ts +174 -70
- package/src/types/sdk.ts +19 -4
package/src/types/quotes.ts
CHANGED
|
@@ -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(),
|
|
@@ -85,6 +224,7 @@ export enum ProviderName {
|
|
|
85
224
|
THORCHAIN = "THORCHAIN",
|
|
86
225
|
THORCHAIN_STREAMING = "THORCHAIN_STREAMING",
|
|
87
226
|
MAYACHAIN = "MAYACHAIN",
|
|
227
|
+
MAYACHAIN_STREAMING = "MAYACHAIN_STREAMING",
|
|
88
228
|
ONEINCH = "ONEINCH",
|
|
89
229
|
SUSHISWAP_V2 = "SUSHISWAP_V2",
|
|
90
230
|
WOOFI_V2 = "WOOFI_V2",
|
|
@@ -181,75 +321,35 @@ export const RouteQuoteWarningSchema = z.array(
|
|
|
181
321
|
}),
|
|
182
322
|
);
|
|
183
323
|
|
|
184
|
-
export
|
|
324
|
+
export type EVMTransaction = z.infer<typeof EVMTransactionSchema>;
|
|
325
|
+
|
|
326
|
+
const QuoteResponseRouteLegItemDev = z.object({
|
|
327
|
+
provider: z.nativeEnum(ProviderName),
|
|
185
328
|
sellAsset: z.string({
|
|
186
329
|
description: "Asset to sell",
|
|
187
330
|
}),
|
|
331
|
+
sellAmount: z.string({
|
|
332
|
+
description: "Sell amount",
|
|
333
|
+
}),
|
|
188
334
|
buyAsset: z.string({
|
|
189
335
|
description: "Asset to buy",
|
|
190
336
|
}),
|
|
191
|
-
provider: z.nativeEnum(ProviderName),
|
|
192
337
|
buyAmount: z.string({
|
|
193
|
-
description: "
|
|
338
|
+
description: "Buy amount",
|
|
194
339
|
}),
|
|
195
340
|
buyAmountMaxSlippage: z.string({
|
|
196
|
-
description: "
|
|
197
|
-
}),
|
|
198
|
-
sellAmount: z.string({
|
|
199
|
-
description: "Amount of asset to sell",
|
|
200
|
-
}),
|
|
201
|
-
sourceAddress: z.string({
|
|
202
|
-
description: "Source address",
|
|
203
|
-
}),
|
|
204
|
-
destinationAddress: z.string({
|
|
205
|
-
description: "Destination address",
|
|
206
|
-
}),
|
|
207
|
-
slippageBps: z.number({
|
|
208
|
-
description: "Slippage in bps",
|
|
341
|
+
description: "Buy amount max slippage",
|
|
209
342
|
}),
|
|
210
|
-
|
|
211
|
-
z.string({
|
|
212
|
-
description: "Target address for contract call or transfer address",
|
|
213
|
-
}),
|
|
214
|
-
),
|
|
215
|
-
inboundAddress: z.optional(
|
|
216
|
-
z.string({
|
|
217
|
-
description: "Inbound address",
|
|
218
|
-
}),
|
|
219
|
-
),
|
|
220
|
-
routerAddress: z.optional(
|
|
221
|
-
z.string({
|
|
222
|
-
description: "Inbound address",
|
|
223
|
-
}),
|
|
224
|
-
),
|
|
225
|
-
contractMethod: z.optional(
|
|
226
|
-
z.string({
|
|
227
|
-
description: "Contract method",
|
|
228
|
-
}),
|
|
229
|
-
),
|
|
230
|
-
fees: z.optional(FeesSchema),
|
|
231
|
-
estimatedTime: z.optional(EstimatedTimeSchema),
|
|
232
|
-
memo: z.optional(
|
|
233
|
-
z.string({
|
|
234
|
-
description: "Memo",
|
|
235
|
-
}),
|
|
236
|
-
),
|
|
237
|
-
expiration: z.optional(
|
|
238
|
-
z.string({
|
|
239
|
-
description: "Expiration",
|
|
240
|
-
}),
|
|
241
|
-
),
|
|
343
|
+
fees: z.optional(FeesSchema), // TODO remove optionality
|
|
242
344
|
});
|
|
243
345
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
export const RouteQuoteSchema = z.object({
|
|
346
|
+
const QuoteResponseRouteItemDev = z.object({
|
|
247
347
|
providers: z.array(z.nativeEnum(ProviderName)),
|
|
248
348
|
sellAsset: z.string({
|
|
249
349
|
description: "Asset to sell",
|
|
250
350
|
}),
|
|
251
351
|
sellAmount: z.string({
|
|
252
|
-
description: "
|
|
352
|
+
description: "Sell amount",
|
|
253
353
|
}),
|
|
254
354
|
buyAsset: z.string({
|
|
255
355
|
description: "Asset to buy",
|
|
@@ -271,16 +371,6 @@ export const RouteQuoteSchema = z.object({
|
|
|
271
371
|
description: "Target address",
|
|
272
372
|
}),
|
|
273
373
|
),
|
|
274
|
-
routerAddress: z.optional(
|
|
275
|
-
z.string({
|
|
276
|
-
description: "Router address",
|
|
277
|
-
}),
|
|
278
|
-
),
|
|
279
|
-
inboundAddress: z.optional(
|
|
280
|
-
z.string({
|
|
281
|
-
description: "Inbound address",
|
|
282
|
-
}),
|
|
283
|
-
),
|
|
284
374
|
expiration: z.optional(
|
|
285
375
|
z.string({
|
|
286
376
|
description: "Expiration",
|
|
@@ -291,20 +381,33 @@ export const RouteQuoteSchema = z.object({
|
|
|
291
381
|
description: "Memo",
|
|
292
382
|
}),
|
|
293
383
|
),
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
|
297
388
|
totalSlippageBps: z.number({
|
|
298
389
|
description: "Total slippage in bps",
|
|
299
390
|
}),
|
|
300
|
-
legs: z.array(
|
|
301
|
-
// TODO use enum
|
|
302
|
-
errorCode: z.optional(z.string()),
|
|
391
|
+
legs: z.array(QuoteResponseRouteLegItemDev),
|
|
303
392
|
warnings: RouteQuoteWarningSchema,
|
|
304
393
|
meta: RouteQuoteMetadataSchema,
|
|
305
394
|
});
|
|
306
395
|
|
|
307
|
-
export
|
|
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>;
|
|
308
411
|
|
|
309
412
|
const QuoteResponseRouteLegItem = z.object({
|
|
310
413
|
provider: z.nativeEnum(ProviderName),
|
|
@@ -332,7 +435,7 @@ const QuoteResponseRouteItem = z.object({
|
|
|
332
435
|
description: "Asset to sell",
|
|
333
436
|
}),
|
|
334
437
|
sellAmount: z.string({
|
|
335
|
-
description: "
|
|
438
|
+
description: "Sell amount",
|
|
336
439
|
}),
|
|
337
440
|
buyAsset: z.string({
|
|
338
441
|
description: "Asset to buy",
|
|
@@ -365,6 +468,7 @@ const QuoteResponseRouteItem = z.object({
|
|
|
365
468
|
}),
|
|
366
469
|
),
|
|
367
470
|
evmTransactionDetails: z.optional(EVMTransactionDetailsSchema),
|
|
471
|
+
transaction: z.optional(z.unknown()), // Can take many forms depending on the chains
|
|
368
472
|
estimatedTime: z.optional(EstimatedTimeSchema), // TODO remove optionality
|
|
369
473
|
totalSlippageBps: z.number({
|
|
370
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
|
|
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
|
|
88
|
-
|
|
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",
|