@swapkit/helpers 3.0.0-beta.0 → 3.0.0-beta.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 (100) hide show
  1. package/dist/api/index.cjs +2 -2
  2. package/dist/api/index.cjs.map +6 -6
  3. package/dist/api/index.js +2 -2
  4. package/dist/api/index.js.map +6 -6
  5. package/dist/chunk-1gwdyyeh.js +4 -0
  6. package/dist/chunk-1gwdyyeh.js.map +10 -0
  7. package/dist/chunk-2bhvezjh.js +4 -0
  8. package/dist/chunk-2bhvezjh.js.map +10 -0
  9. package/dist/chunk-3ptwhtpd.js +3 -0
  10. package/dist/chunk-3ptwhtpd.js.map +10 -0
  11. package/dist/{chunk-nm00d52v.js → chunk-3wnfcm30.js} +2 -2
  12. package/dist/{chunk-nm00d52v.js.map → chunk-3wnfcm30.js.map} +1 -1
  13. package/dist/chunk-40epvqbm.js +3 -0
  14. package/dist/chunk-40epvqbm.js.map +10 -0
  15. package/dist/chunk-49nsjaay.js +3 -0
  16. package/dist/chunk-49nsjaay.js.map +10 -0
  17. package/dist/chunk-4b66tryh.js +4 -0
  18. package/dist/chunk-4b66tryh.js.map +10 -0
  19. package/dist/chunk-4kzjrrjv.js +3 -0
  20. package/dist/chunk-4kzjrrjv.js.map +10 -0
  21. package/dist/chunk-5m49s8z8.js +4 -0
  22. package/dist/chunk-5m49s8z8.js.map +10 -0
  23. package/dist/chunk-9b6y7r75.js +4 -0
  24. package/dist/chunk-9b6y7r75.js.map +10 -0
  25. package/dist/chunk-9zcbvqq2.js +3 -0
  26. package/dist/chunk-9zcbvqq2.js.map +10 -0
  27. package/dist/chunk-a0bpx1q3.js +4 -0
  28. package/dist/chunk-a0bpx1q3.js.map +10 -0
  29. package/dist/chunk-a0fxkkfh.js +4 -0
  30. package/dist/chunk-a0fxkkfh.js.map +10 -0
  31. package/dist/chunk-a6bjd9ar.js +3 -0
  32. package/dist/chunk-a6bjd9ar.js.map +10 -0
  33. package/dist/chunk-bg6pz5qh.js +3 -0
  34. package/dist/chunk-bg6pz5qh.js.map +10 -0
  35. package/dist/chunk-cpdcnp2x.js +4 -0
  36. package/dist/chunk-cpdcnp2x.js.map +10 -0
  37. package/dist/chunk-fr86y3rx.js +4 -0
  38. package/dist/chunk-fr86y3rx.js.map +10 -0
  39. package/dist/chunk-ftdtdkhk.js +3 -0
  40. package/dist/chunk-ftdtdkhk.js.map +10 -0
  41. package/dist/chunk-gjeaw024.js +4 -0
  42. package/dist/chunk-gjeaw024.js.map +10 -0
  43. package/dist/chunk-hdcdd2cf.js +4 -0
  44. package/dist/chunk-hdcdd2cf.js.map +10 -0
  45. package/dist/chunk-q2pb6ggs.js +3 -0
  46. package/dist/chunk-q2pb6ggs.js.map +10 -0
  47. package/dist/chunk-t9s9811k.js +3 -0
  48. package/dist/chunk-t9s9811k.js.map +10 -0
  49. package/dist/chunk-v4dvhh90.js +4 -0
  50. package/dist/chunk-v4dvhh90.js.map +10 -0
  51. package/dist/chunk-vzptz52h.js +4 -0
  52. package/dist/chunk-vzptz52h.js.map +10 -0
  53. package/dist/chunk-wyr5d8ad.js +3 -0
  54. package/dist/chunk-wyr5d8ad.js.map +10 -0
  55. package/dist/chunk-x0jsq6ag.js +3 -0
  56. package/dist/chunk-x0jsq6ag.js.map +10 -0
  57. package/dist/chunk-x2fe9scs.js +3 -0
  58. package/dist/chunk-x2fe9scs.js.map +10 -0
  59. package/dist/chunk-xm5jkehh.js +4 -0
  60. package/dist/chunk-xm5jkehh.js.map +10 -0
  61. package/dist/chunk-xzb1nshn.js +3 -0
  62. package/dist/chunk-xzb1nshn.js.map +10 -0
  63. package/dist/contracts/index.cjs.map +2 -2
  64. package/dist/contracts/index.js +1 -1
  65. package/dist/contracts/index.js.map +2 -2
  66. package/dist/index.cjs +3 -3
  67. package/dist/index.cjs.map +19 -18
  68. package/dist/index.js +3 -3
  69. package/dist/index.js.map +19 -18
  70. package/dist/tokens/index.cjs +2 -2
  71. package/dist/tokens/index.cjs.map +3 -16
  72. package/dist/tokens/index.js +2 -2
  73. package/dist/tokens/index.js.map +3 -16
  74. package/package.json +8 -5
  75. package/src/api/midgard/endpoints.ts +120 -132
  76. package/src/api/swapkitApi/endpoints.ts +53 -158
  77. package/src/api/swapkitApi/types.ts +318 -514
  78. package/src/api/thorswapStatic/endpoints.ts +18 -2
  79. package/src/contracts/index.ts +1 -1
  80. package/src/index.ts +15 -10
  81. package/src/modules/__tests__/assetValue.test.ts +50 -22
  82. package/src/modules/__tests__/swapKitConfig.test.ts +3 -3
  83. package/src/modules/assetValue.ts +77 -67
  84. package/src/modules/requestClient.ts +52 -55
  85. package/src/modules/swapKitConfig.ts +8 -5
  86. package/src/modules/swapKitError.ts +18 -11
  87. package/src/tokens/lists/index.ts +1 -0
  88. package/src/types/chains.ts +22 -5
  89. package/src/types/commonTypes.ts +1 -1
  90. package/src/types/derivationPath.ts +11 -24
  91. package/src/types/radix.ts +2 -2
  92. package/src/types/sdk.ts +0 -7
  93. package/src/types/tokens.ts +13 -16
  94. package/src/types/wallet.ts +42 -21
  95. package/src/utils/asset.ts +118 -217
  96. package/src/utils/derivationPath.ts +24 -7
  97. package/src/utils/plugin.ts +1 -1
  98. package/src/utils/tokens.ts +73 -0
  99. package/src/utils/validators.ts +3 -2
  100. package/src/utils/wallets.ts +19 -10
@@ -7,7 +7,19 @@ import {
7
7
  ProviderName,
8
8
  WarningCodeEnum,
9
9
  } from "@swapkit/helpers";
10
- import { z } from "zod";
10
+ import {
11
+ type ZodType,
12
+ array,
13
+ boolean,
14
+ nativeEnum,
15
+ number,
16
+ object,
17
+ optional,
18
+ string,
19
+ union,
20
+ unknown,
21
+ type z,
22
+ } from "zod";
11
23
 
12
24
  export enum PriorityLabel {
13
25
  CHEAPEST = "CHEAPEST",
@@ -23,39 +35,38 @@ export enum RouteQuoteTxType {
23
35
  }
24
36
 
25
37
  export enum TxnType {
26
- native_send = "native_send", // native send, msgSend, etc.
27
- token_transfer = "token_transfer", // token transfer
28
- native_contract_call = "native_contract_call", // native contract call
29
- token_contract_call = "token_contract_call", // token contract call
30
- approve = "approve", // token approve
31
- deposit = "deposit", // msgDeposit and related cosmos operations, not deposit to vault or deposit contract name
32
- thorname_action = "thorname_action", // should we use this or msgDeposit?
33
- lp_action = "lp_action", // deposit to an evm pool, tc pool, etc.
34
- swap = "swap", // any kind of operations that involves swapping assets
35
- streaming_swap = "streaming_swap", // streaming swap
36
- stake = "stake", // defi operations like $vthor and other types of staking
37
- claim = "claim", // claim rewards, claim tokens, etc.
38
- lending = "lending", // lending operations
38
+ native_send = "native_send",
39
+ token_transfer = "token_transfer",
40
+ native_contract_call = "native_contract_call",
41
+ token_contract_call = "token_contract_call",
42
+ approve = "approve",
43
+ deposit = "deposit",
44
+ thorname_action = "thorname_action",
45
+ lp_action = "lp_action",
46
+ swap = "swap",
47
+ streaming_swap = "streaming_swap",
48
+ stake = "stake",
49
+ claim = "claim",
50
+ lending = "lending",
39
51
  unknown = "unknown",
40
52
  }
41
53
 
42
- // transaction status devoid of any business logic
43
54
  export enum TxnStatus {
44
55
  unknown = "unknown",
45
56
  not_started = "not_started",
46
57
  pending = "pending",
47
- swappping = "swapping",
58
+ swapping = "swapping",
48
59
  completed = "completed",
49
60
  }
50
61
 
51
62
  export enum TrackingStatus {
52
63
  not_started = "not_started",
53
- starting = "starting", // first status once we receive, old or new transaction
64
+ starting = "starting",
54
65
  broadcasted = "broadcasted",
55
- mempool = "mempool", // or indexing
66
+ mempool = "mempool",
56
67
  inbound = "inbound",
57
68
  outbound = "outbound",
58
- swapping = "swapping", // more generic than streaming
69
+ swapping = "swapping",
59
70
  completed = "completed",
60
71
  refunded = "refunded",
61
72
  partially_refunded = "partially_refunded",
@@ -134,465 +145,321 @@ export type TrackerResponse = TransactionProps & {
134
145
  transient?: TxnTransient;
135
146
  };
136
147
 
137
- export const ApiV2ErrorSchema = z.object({
138
- error: z.string(),
139
- message: z.string(),
148
+ export const ApiV2ErrorSchema = object({
149
+ error: string(),
150
+ message: string(),
140
151
  });
141
152
 
142
- export const AssetValueSchema = z.object({
143
- chain: z.nativeEnum(Chain),
144
- symbol: z.string(),
145
- ticker: z.string(),
146
- decimal: z.optional(z.number()),
147
- address: z.optional(z.string()),
148
- isGasAsset: z.boolean(),
149
- isSynthetic: z.boolean(),
150
- tax: z.optional(
151
- z.object({
152
- buy: z.number(),
153
- sell: z.number(),
154
- }),
155
- ),
153
+ export const AssetValueSchema = object({
154
+ chain: nativeEnum(Chain),
155
+ symbol: string(),
156
+ ticker: string(),
157
+ decimal: optional(number()),
158
+ address: optional(string()),
159
+ isGasAsset: boolean(),
160
+ isSynthetic: boolean(),
161
+ tax: optional(object({ buy: number(), sell: number() })),
156
162
  });
157
163
 
158
- export const TokenDetailsMetadataSchema = z.object({
159
- name: z.string(),
160
- id: z.string(),
161
- market_cap: z.number(),
162
- total_volume: z.number(),
163
- price_change_24h_usd: z.number(),
164
- price_change_percentage_24h_usd: z.number(),
165
- timestamp: z.string(),
166
- sparkline_in_7d: z.array(z.number()),
164
+ export const TokenDetailsMetadataSchema = object({
165
+ id: string(),
166
+ market_cap: number(),
167
+ name: string(),
168
+ price_change_24h_usd: number(),
169
+ price_change_percentage_24h_usd: number(),
170
+ sparkline_in_7d: array(number()),
171
+ timestamp: string(),
172
+ total_volume: number(),
167
173
  });
168
174
 
169
- export const PriceResponseSchema = z.array(
170
- z
171
- .object({
172
- identifier: z.string(),
173
- provider: z.string(),
174
- cg: TokenDetailsMetadataSchema.optional(),
175
- price_usd: z.number(),
176
- timestamp: z.number(),
177
- })
178
- .partial(),
175
+ export const PriceResponseSchema = array(
176
+ object({
177
+ identifier: string(),
178
+ provider: string(),
179
+ cg: TokenDetailsMetadataSchema.optional(),
180
+ price_usd: number(),
181
+ timestamp: number(),
182
+ }).partial(),
179
183
  );
180
184
 
181
185
  export type PriceResponse = z.infer<typeof PriceResponseSchema>;
182
186
 
183
- export const QuoteRequestSchema = z
184
- .object({
185
- sellAsset: z.string({
186
- description: "Asset to sell",
187
- }),
188
- buyAsset: z.string({
189
- description: "Asset to buy",
190
- }),
191
- sellAmount: z
192
- .string({
193
- description: "Amount of asset to sell",
194
- })
195
- .refine((amount) => +amount > 0, {
196
- message: "sellAmount must be greater than 0",
197
- path: ["sellAmount"],
198
- }),
199
- providers: z.optional(
200
- z.array(
201
- z
202
- .string({
203
- description: "List of providers to use",
204
- })
205
- .refine(
206
- (provider) => {
207
- return ProviderName[provider as ProviderName] !== undefined;
208
- },
209
- {
210
- message: "Invalid provider",
211
- path: ["providers"],
212
- },
213
- ),
187
+ export const QuoteRequestSchema = object({
188
+ sellAsset: string({ description: "Asset to sell" }),
189
+ buyAsset: string({ description: "Asset to buy" }),
190
+ sellAmount: string({ description: "Amount of asset to sell" }).refine((amount) => +amount > 0, {
191
+ message: "sellAmount must be greater than 0",
192
+ path: ["sellAmount"],
193
+ }),
194
+ providers: optional(
195
+ array(
196
+ string({ description: "List of providers to use" }).refine(
197
+ (provider) => ProviderName[provider as ProviderName] !== undefined,
198
+ { message: "Invalid provider", path: ["providers"] },
214
199
  ),
215
200
  ),
216
- sourceAddress: z.optional(
217
- z.string({
218
- description: "Address to send asset from",
219
- }),
220
- ),
221
- destinationAddress: z.optional(
222
- z.string({
223
- description: "Address to send asset to",
224
- }),
225
- ),
226
- slippage: z.optional(
227
- z.number({
228
- description: "Slippage tolerance as a percentage. Default is 3%.",
229
- }),
230
- ),
231
- affiliate: z.optional(
232
- z.string({
233
- description: "Affiliate thorname",
234
- }),
235
- ),
236
- affiliateFee: z.optional(
237
- z
238
- .number({
239
- description: "Affiliate fee in basis points",
240
- })
241
- .refine(
242
- (fee) => {
243
- return fee === Math.floor(fee) && fee >= 0;
244
- },
245
- {
246
- message: "affiliateFee must be a positive integer",
247
- path: ["affiliateFee"],
248
- },
249
- ),
250
- ),
251
- allowSmartContractSender: z.optional(
252
- z.boolean({
253
- description: "Allow smart contract as sender",
254
- }),
255
- ),
256
- allowSmartContractReceiver: z.optional(
257
- z.boolean({
258
- description: "Allow smart contract as recipient",
259
- }),
260
- ),
261
- disableSecurityChecks: z.optional(
262
- z.boolean({
263
- description: "Disable security checks",
264
- }),
265
- ),
266
- includeTx: z.optional(
267
- z.boolean({
268
- description: "Set to true to include an transaction object (EVM only)",
269
- }),
270
- ),
271
- cfBoost: z.optional(
272
- z.boolean({
273
- description: "Set to true to enable CF boost to speed up Chainflip swaps. BTC only.",
274
- }),
275
- ),
276
- referrer: z.optional(
277
- z.string({
278
- description: "Referrer address (referral program)",
279
- }),
201
+ ),
202
+ sourceAddress: optional(string({ description: "Address to send asset from" })),
203
+ destinationAddress: optional(string({ description: "Address to send asset to" })),
204
+ slippage: optional(number({ description: "Slippage tolerance as a percentage. Default is 3%." })),
205
+ affiliate: optional(string({ description: "Affiliate thorname" })),
206
+ affiliateFee: optional(
207
+ number({ description: "Affiliate fee in basis points" }).refine(
208
+ (fee) => fee === Math.floor(fee) && fee >= 0,
209
+ { message: "affiliateFee must be a positive integer", path: ["affiliateFee"] },
280
210
  ),
281
- })
282
- .refine((data) => data.sellAsset !== data.buyAsset, {
283
- message: "Must be different",
284
- path: ["sellAsset", "buyAsset"],
285
- });
211
+ ),
212
+ allowSmartContractSender: optional(boolean({ description: "Allow smart contract as sender" })),
213
+ allowSmartContractReceiver: optional(
214
+ boolean({ description: "Allow smart contract as recipient" }),
215
+ ),
216
+ disableSecurityChecks: optional(boolean({ description: "Disable security checks" })),
217
+ includeTx: optional(
218
+ boolean({ description: "Set to true to include an transaction object (EVM only)" }),
219
+ ),
220
+ cfBoost: optional(
221
+ boolean({
222
+ description: "Set to true to enable CF boost to speed up Chainflip swaps. BTC only.",
223
+ }),
224
+ ),
225
+ referrer: optional(string({ description: "Referrer address (referral program)" })),
226
+ }).refine((data) => data.sellAsset !== data.buyAsset, {
227
+ message: "Must be different",
228
+ path: ["sellAsset", "buyAsset"],
229
+ });
286
230
 
287
231
  export type QuoteRequest = z.infer<typeof QuoteRequestSchema>;
288
232
 
289
- export const PriceRequestSchema = z.object({
290
- tokens: z.array(
291
- z.object({
292
- identifier: z.string(),
233
+ export const PriceRequestSchema = object({
234
+ tokens: array(
235
+ object({
236
+ identifier: string(),
293
237
  }),
294
238
  ),
295
- metadata: z.boolean(),
239
+ metadata: boolean(),
296
240
  });
297
241
 
298
242
  export type PriceRequest = z.infer<typeof PriceRequestSchema>;
299
243
 
300
- export const BrokerDepositChannelParamsSchema = z.object({
301
- sellAsset: z.object({
302
- chain: z.string(), // identifier of the asset
303
- asset: z.string(), // identifier of the asset
304
- }),
305
- buyAsset: z.object({
306
- chain: z.string(), // identifier of the asset
307
- asset: z.string(), // identifier of the asset
308
- }),
309
- destinationAddress: z.string(),
310
- channelMetadata: z
311
- .object({
312
- cfParameters: z.string().optional(),
313
- gasBudget: z.string().optional(),
314
- message: z.string().optional(),
315
- })
316
- .optional(),
317
- affiliateFees: z
318
- .array(
319
- z.object({
320
- brokerAddress: z.string(),
321
- feeBps: z.number(),
322
- }),
323
- )
324
- .optional(),
325
- refundParameters: z
326
- .object({
327
- minPrice: z.string().optional(),
328
- refundAddress: z.string().optional(),
329
- retryDuration: z.number().optional(),
330
- })
331
- .optional(),
332
- dcaParameters: z
333
- .object({
334
- chunkInterval: z.number().optional(),
335
- numberOfChunks: z.number().optional(),
336
- })
337
- .optional(),
338
- brokerCommissionBps: z.number().optional(),
339
- maxBoostFeeBps: z.number().optional(),
244
+ export const BrokerDepositChannelParamsSchema = object({
245
+ sellAsset: object({
246
+ chain: string(),
247
+ asset: string(),
248
+ }),
249
+ buyAsset: object({
250
+ chain: string(),
251
+ asset: string(), // identifier of the asset
252
+ }),
253
+ destinationAddress: string(),
254
+ channelMetadata: object({
255
+ cfParameters: string().optional(),
256
+ gasBudget: string().optional(),
257
+ message: string().optional(),
258
+ }).optional(),
259
+ affiliateFees: array(
260
+ object({
261
+ brokerAddress: string(),
262
+ feeBps: number(),
263
+ }),
264
+ ).optional(),
265
+ refundParameters: object({
266
+ minPrice: string().optional(),
267
+ refundAddress: string().optional(),
268
+ retryDuration: number().optional(),
269
+ }).optional(),
270
+ dcaParameters: object({
271
+ chunkInterval: number().optional(),
272
+ numberOfChunks: number().optional(),
273
+ }).optional(),
274
+ brokerCommissionBps: number().optional(),
275
+ maxBoostFeeBps: number().optional(),
340
276
  });
341
277
 
342
278
  export type BrokerDepositChannelParams = z.infer<typeof BrokerDepositChannelParamsSchema>;
343
279
 
344
- export const DepositChannelResponseSchema = z.object({
345
- channelId: z.string(),
346
- depositAddress: z.string(),
280
+ export const DepositChannelResponseSchema = object({
281
+ channelId: string(),
282
+ depositAddress: string(),
347
283
  });
348
284
 
349
285
  export type DepositChannelResponse = z.infer<typeof DepositChannelResponseSchema>;
350
286
 
351
- const TxnPayloadSchema = z.object({
352
- evmCalldata: z.optional(z.string()), // raw 0xcalldata
353
- logs: z.optional(z.unknown()),
354
- memo: z.optional(z.string()),
355
- spender: z.optional(z.string()), // used in evm approve transactions
287
+ const TxnPayloadSchema = object({
288
+ evmCalldata: optional(string()),
289
+ logs: optional(unknown()),
290
+ memo: optional(string()),
291
+ spender: optional(string()), // used in evm approve transactions
356
292
  });
357
293
 
358
294
  export type TxnPayload = z.infer<typeof TxnPayloadSchema>;
359
295
 
360
296
  // props that are most important while the transaction is live
361
- const TxnTransientSchema = z.object({
362
- estimatedfinalisedAt: z.number(),
363
- estimatedTimeToComplete: z.number(),
364
- updatedAt: z.number(),
365
- currentLegIndex: z.optional(z.number()),
366
- providerDetails: z.optional(z.unknown()), // see ProviderTransientDetails
297
+ const TxnTransientSchema = object({
298
+ estimatedFinalisedAt: number(),
299
+ estimatedTimeToComplete: number(),
300
+ updatedAt: number(),
301
+ currentLegIndex: optional(number()),
302
+ providerDetails: optional(unknown()), // see ProviderTransientDetails
367
303
  });
368
304
 
369
305
  export type TxnTransient = z.infer<typeof TxnTransientSchema>;
370
306
 
371
- const TransactionFeesSchema = z.object({
372
- network: z.optional(AssetValueSchema), // gas on ethereum, network fee on thorchain, etc.
373
- affiliate: z.optional(AssetValueSchema), // e.g. affiliate in memo, other affiliate mechanisms
374
- liquidity: z.optional(AssetValueSchema), // fee paid to pool
375
- protocol: z.optional(AssetValueSchema), // extra protocol fees (TS dex aggregation contracts, stargate fees, etc.)
376
- tax: z.optional(AssetValueSchema), // taxed tokens
307
+ const TransactionFeesSchema = object({
308
+ network: optional(AssetValueSchema), // gas on ethereum, network fee on thorchain, etc.
309
+ affiliate: optional(AssetValueSchema), // e.g. affiliate in memo, other affiliate mechanisms
310
+ liquidity: optional(AssetValueSchema), // fee paid to pool
311
+ protocol: optional(AssetValueSchema), // extra protocol fees (TS dex aggregation contracts, stargate fees, etc.)
312
+ tax: optional(AssetValueSchema), // taxed tokens
377
313
  });
378
314
 
379
315
  export type TransactionFees = z.infer<typeof TransactionFeesSchema>;
380
316
 
381
- // props that are not part of the transaction itself, but are still relevant for integrators
382
- const TxnMetaSchema = z.object({
383
- broadcastedAt: z.optional(z.number()),
384
- wallet: z.optional(z.string()),
385
- quoteId: z.optional(z.string()),
386
- explorerUrl: z.optional(z.string()),
387
- affiliate: z.optional(z.string()),
388
- fees: z.optional(TransactionFeesSchema),
389
- provider: z.optional(z.nativeEnum(ProviderName)),
390
- images: z.optional(
391
- z.object({
392
- from: z.optional(z.string()),
393
- to: z.optional(z.string()),
394
- provider: z.optional(z.string()),
395
- chain: z.optional(z.string()),
317
+ const TxnMetaSchema = object({
318
+ broadcastedAt: optional(number()),
319
+ wallet: optional(string()),
320
+ quoteId: optional(string()),
321
+ explorerUrl: optional(string()),
322
+ affiliate: optional(string()),
323
+ fees: optional(TransactionFeesSchema),
324
+ provider: optional(nativeEnum(ProviderName)),
325
+ images: optional(
326
+ object({
327
+ from: optional(string()),
328
+ to: optional(string()),
329
+ provider: optional(string()),
330
+ chain: optional(string()),
396
331
  }),
397
332
  ),
398
333
  });
399
334
 
400
335
  export type TxnMeta = z.infer<typeof TxnMetaSchema>;
401
336
 
402
- const TransactionLegDTOSchema = z.object({
403
- chainId: z.nativeEnum(ChainId),
404
- hash: z.string(),
405
- block: z.number(),
406
- type: z.nativeEnum(TxnType),
407
- status: z.nativeEnum(TxnStatus),
408
- trackingStatus: z.optional(z.nativeEnum(TrackingStatus)),
409
-
410
- fromAsset: z.string(),
411
- fromAmount: z.string(),
412
- fromAddress: z.string(),
413
- toAsset: z.string(),
414
- toAmount: z.string(),
415
- toAddress: z.string(),
416
- finalAsset: z.optional(AssetValueSchema),
417
- finalAddress: z.optional(z.string()),
418
-
419
- finalisedAt: z.number(),
420
-
421
- transient: z.optional(TxnTransientSchema),
422
- meta: z.optional(TxnMetaSchema),
423
- payload: z.optional(TxnPayloadSchema),
337
+ const TransactionLegDTOSchema = object({
338
+ chainId: nativeEnum(ChainId),
339
+ hash: string(),
340
+ block: number(),
341
+ type: nativeEnum(TxnType),
342
+ status: nativeEnum(TxnStatus),
343
+ trackingStatus: optional(nativeEnum(TrackingStatus)),
344
+
345
+ fromAsset: string(),
346
+ fromAmount: string(),
347
+ fromAddress: string(),
348
+ toAsset: string(),
349
+ toAmount: string(),
350
+ toAddress: string(),
351
+ finalAsset: optional(AssetValueSchema),
352
+ finalAddress: optional(string()),
353
+
354
+ finalisedAt: number(),
355
+
356
+ transient: optional(TxnTransientSchema),
357
+ meta: optional(TxnMetaSchema),
358
+ payload: optional(TxnPayloadSchema),
424
359
  });
425
360
 
426
361
  export type TransactionLegDTO = z.infer<typeof TransactionLegDTOSchema>;
427
362
 
428
363
  export const TransactionSchema = TransactionLegDTOSchema.extend({
429
- legs: z.array(TransactionLegDTOSchema),
364
+ legs: array(TransactionLegDTOSchema),
430
365
  });
431
366
 
432
367
  export type TransactionDTO = z.infer<typeof TransactionLegDTOSchema> & {
433
368
  legs: TransactionLegDTO[];
434
369
  };
435
370
 
436
- export const TransactionDTOSchema: z.ZodType<TransactionDTO> = TransactionLegDTOSchema.extend({
437
- legs: z.array(TransactionLegDTOSchema),
371
+ export const TransactionDTOSchema: ZodType<TransactionDTO> = TransactionLegDTOSchema.extend({
372
+ legs: array(TransactionLegDTOSchema),
438
373
  });
439
374
 
440
- export const FeesSchema = z.array(
441
- z.object({
442
- type: z.nativeEnum(FeeTypeEnum),
443
- amount: z.string(),
444
- asset: z.string(),
445
- chain: z.string(),
446
- protocol: z.nativeEnum(ProviderName),
375
+ export const FeesSchema = array(
376
+ object({
377
+ type: nativeEnum(FeeTypeEnum),
378
+ amount: string(),
379
+ asset: string(),
380
+ chain: string(),
381
+ protocol: nativeEnum(ProviderName),
447
382
  }),
448
383
  );
449
384
 
450
385
  export type Fees = z.infer<typeof FeesSchema>;
451
386
 
452
- export const EstimatedTimeSchema = z.object({
453
- inbound: z.optional(
454
- z.number({
455
- description: "Time to receive inbound asset in seconds",
456
- }),
457
- ),
458
- swap: z.optional(
459
- z.number({
460
- description: "Time to swap assets in seconds",
461
- }),
462
- ),
463
- outbound: z.optional(
464
- z.number({
465
- description: "Time to receive outbound asset in seconds",
466
- }),
467
- ),
468
- total: z.number({
469
- description: "Total time in seconds",
470
- }),
387
+ export const EstimatedTimeSchema = object({
388
+ inbound: optional(number({ description: "Time to receive inbound asset in seconds" })),
389
+ swap: optional(number({ description: "Time to swap assets in seconds" })),
390
+ outbound: optional(number({ description: "Time to receive outbound asset in seconds" })),
391
+ total: number({ description: "Total time in seconds" }),
471
392
  });
472
393
 
473
394
  export type EstimatedTime = z.infer<typeof EstimatedTimeSchema>;
474
395
 
475
- export const EVMTransactionSchema = z.object({
476
- to: z.string({
477
- description: "Address of the recipient",
478
- }),
479
- from: z.string({
480
- description: "Address of the sender",
481
- }),
482
- value: z.string({
483
- description: "Value to send",
484
- }),
485
- data: z.string({
486
- description: "Data to send",
487
- }),
396
+ export const EVMTransactionSchema = object({
397
+ to: string({ description: "Address of the recipient" }),
398
+ from: string({ description: "Address of the sender" }),
399
+ value: string({ description: "Value to send" }),
400
+ data: string({ description: "Data to send" }),
488
401
  });
489
402
 
490
403
  export type EVMTransaction = z.infer<typeof EVMTransactionSchema>;
491
404
 
492
- export const EVMTransactionDetailsParamsSchema = z.array(
493
- z.union([
494
- z.string(),
495
- z.number(),
496
- z.array(z.string()),
497
- z
498
- .object({
499
- from: z.string(),
500
- value: z.string(),
501
- })
502
- .describe("Parameters to pass to the contract method"),
405
+ export const EVMTransactionDetailsParamsSchema = array(
406
+ union([
407
+ string(),
408
+ number(),
409
+ array(string()),
410
+
411
+ object({ from: string(), value: string() }).describe(
412
+ "Parameters to pass to the contract method",
413
+ ),
503
414
  ]),
504
415
  );
505
416
 
506
417
  export type EVMTransactionDetailsParams = z.infer<typeof EVMTransactionDetailsParamsSchema>;
507
418
 
508
- export const EVMTransactionDetailsSchema = z.object({
509
- contractAddress: z.string({
510
- description: "Address of the contract to interact with",
511
- }),
512
- contractMethod: z.string({
513
- description: "Name of the method to call",
514
- }),
419
+ export const EVMTransactionDetailsSchema = object({
420
+ contractAddress: string({ description: "Address of the contract to interact with" }),
421
+ contractMethod: string({ description: "Name of the method to call" }),
515
422
  contractParams: EVMTransactionDetailsParamsSchema,
516
- // contractParamsStreaming: z.array(
517
- // z.string({
518
- // description:
519
- // "If making a streaming swap through THORChain, parameters to pass to the contract method",
520
- // }),
521
- // ),
522
- contractParamNames: z.array(
523
- z.string({
524
- description: "Names of the parameters to pass to the contract method",
525
- }),
526
- ),
527
- approvalToken: z.optional(
528
- z.string({
529
- description: "Address of the token to approve spending of",
530
- }),
531
- ),
532
- approvalSpender: z.optional(
533
- z.string({
534
- description: "Address of the spender to approve",
535
- }),
423
+ contractParamNames: array(
424
+ string({ description: "Names of the parameters to pass to the contract method" }),
536
425
  ),
426
+ approvalToken: optional(string({ description: "Address of the token to approve spending of" })),
427
+ approvalSpender: optional(string({ description: "Address of the spender to approve" })),
537
428
  });
538
429
 
539
430
  export type EVMTransactionDetails = z.infer<typeof EVMTransactionDetailsSchema>;
540
431
 
541
- const EncodeObjectSchema = z.object({
542
- typeUrl: z.string(),
543
- value: z.unknown(),
432
+ const EncodeObjectSchema = object({
433
+ typeUrl: string(),
434
+ value: unknown(),
544
435
  });
545
436
 
546
- const FeeSchema = z.object({
547
- amount: z.array(
548
- z.object({
549
- denom: z.string(),
550
- amount: z.string(),
551
- }),
552
- ),
553
- gas: z.string(),
437
+ const FeeSchema = object({
438
+ amount: array(object({ denom: string(), amount: string() })),
439
+ gas: string(),
554
440
  });
555
441
 
556
- // Define the full schema
557
- export const CosmosTransactionSchema = z.object({
558
- memo: z.string(),
559
- accountNumber: z.number(),
560
- sequence: z.number(),
561
- chainId: z.nativeEnum(ChainId),
562
- msgs: z.array(EncodeObjectSchema),
442
+ export const CosmosTransactionSchema = object({
443
+ memo: string(),
444
+ accountNumber: number(),
445
+ sequence: number(),
446
+ chainId: nativeEnum(ChainId),
447
+ msgs: array(EncodeObjectSchema),
563
448
  fee: FeeSchema,
564
449
  });
565
450
 
566
451
  export type CosmosTransaction = z.infer<typeof CosmosTransactionSchema>;
567
452
 
568
- export const RouteLegSchema = z.object({
569
- sellAsset: z.string({
570
- description: "Asset to sell",
571
- }),
572
- buyAsset: z.string({
573
- description: "Asset to buy",
574
- }),
575
- provider: z.nativeEnum(ProviderName),
576
- sourceAddress: z.string({
577
- description: "Source address",
578
- }),
579
- destinationAddress: z.string({
580
- description: "Destination address",
581
- }),
453
+ export const RouteLegSchema = object({
454
+ sellAsset: string({ description: "Asset to sell" }),
455
+ buyAsset: string({ description: "Asset to buy" }),
456
+ provider: nativeEnum(ProviderName),
457
+ sourceAddress: string({ description: "Source address" }),
458
+ destinationAddress: string({ description: "Destination address" }),
582
459
  estimatedTime: EstimatedTimeSchema.optional(),
583
- affiliate: z
584
- .string({
585
- description: "Affiliate address",
586
- })
587
- .optional(),
588
- affiliateFee: z
589
- .number({
590
- description: "Affiliate fee",
591
- })
592
- .optional(),
593
- slipPercentage: z.number({
594
- description: "Slippage as a percentage",
595
- }),
460
+ affiliate: string({ description: "Affiliate address" }).optional(),
461
+ affiliateFee: number({ description: "Affiliate fee" }).optional(),
462
+ slipPercentage: number({ description: "Slippage as a percentage" }),
596
463
  });
597
464
 
598
465
  export type RouteLeg = z.infer<typeof RouteLegSchema>;
@@ -605,16 +472,10 @@ export const RouteLegWithoutAddressesSchema = RouteLegSchema.omit({
605
472
 
606
473
  export type RouteLegWithoutAddresses = z.infer<typeof RouteLegWithoutAddressesSchema>;
607
474
 
608
- export const RouteQuoteMetadataAssetSchema = z.object({
609
- asset: z.string({
610
- description: "Asset name",
611
- }),
612
- price: z.number({
613
- description: "Price in USD",
614
- }),
615
- image: z.string({
616
- description: "Asset image",
617
- }),
475
+ export const RouteQuoteMetadataAssetSchema = object({
476
+ asset: string({ description: "Asset name" }),
477
+ price: number({ description: "Price in USD" }),
478
+ image: string({ description: "Asset image" }),
618
479
  });
619
480
 
620
481
  export type RouteQuoteMetadataAsset = z.infer<typeof RouteQuoteMetadataAssetSchema>;
@@ -623,133 +484,69 @@ export const ChainflipMetadataSchema = BrokerDepositChannelParamsSchema;
623
484
 
624
485
  export type ChainflipMetadata = z.infer<typeof ChainflipMetadataSchema>;
625
486
 
626
- export const RouteQuoteMetadataSchema = z.object({
627
- priceImpact: z.optional(
628
- z.number({
629
- description: "Price impact",
630
- }),
631
- ),
632
- assets: z.optional(z.array(RouteQuoteMetadataAssetSchema)),
633
- approvalAddress: z.optional(
634
- z.string({
635
- description: "Approval address for swap",
636
- }),
637
- ),
638
- streamingInterval: z.number().optional(),
639
- maxStreamingQuantity: z.number().optional(),
640
- tags: z.array(z.nativeEnum(PriorityLabel)),
641
-
642
- affiliate: z.optional(z.string()),
643
- affiliateFee: z.optional(z.string()),
644
-
645
- txType: z.optional(z.nativeEnum(RouteQuoteTxType)),
646
- chainflip: z.optional(ChainflipMetadataSchema),
647
- referrer: z.optional(z.string()),
487
+ export const RouteQuoteMetadataSchema = object({
488
+ priceImpact: optional(number({ description: "Price impact" })),
489
+ assets: optional(array(RouteQuoteMetadataAssetSchema)),
490
+ approvalAddress: optional(string({ description: "Approval address for swap" })),
491
+ streamingInterval: number().optional(),
492
+ maxStreamingQuantity: number().optional(),
493
+ tags: array(nativeEnum(PriorityLabel)),
494
+ affiliate: optional(string()),
495
+ affiliateFee: optional(string()),
496
+ txType: optional(nativeEnum(RouteQuoteTxType)),
497
+ chainflip: optional(ChainflipMetadataSchema),
498
+ referrer: optional(string()),
648
499
  });
649
500
 
650
- export const RouteQuoteWarningSchema = z.array(
651
- z.object({
652
- code: z.nativeEnum(WarningCodeEnum),
653
- display: z.string(),
654
- tooltip: z.string().optional(),
655
- }),
501
+ export const RouteQuoteWarningSchema = array(
502
+ object({ code: nativeEnum(WarningCodeEnum), display: string(), tooltip: string().optional() }),
656
503
  );
657
504
 
658
505
  export type RouteQuoteWarning = z.infer<typeof RouteQuoteWarningSchema>;
659
506
 
660
- const QuoteResponseRouteLegItem = z.object({
661
- provider: z.nativeEnum(ProviderName),
662
- sellAsset: z.string({
663
- description: "Asset to sell",
664
- }),
665
- sellAmount: z.string({
666
- description: "Sell amount",
667
- }),
668
- buyAsset: z.string({
669
- description: "Asset to buy",
670
- }),
671
- buyAmount: z.string({
672
- description: "Buy amount",
673
- }),
674
- buyAmountMaxSlippage: z.string({
675
- description: "Buy amount max slippage",
676
- }),
677
- fees: z.optional(FeesSchema), // TODO remove optionality
507
+ const QuoteResponseRouteLegItem = object({
508
+ provider: nativeEnum(ProviderName),
509
+ sellAsset: string({ description: "Asset to sell" }),
510
+ sellAmount: string({ description: "Sell amount" }),
511
+ buyAsset: string({ description: "Asset to buy" }),
512
+ buyAmount: string({ description: "Buy amount" }),
513
+ buyAmountMaxSlippage: string({ description: "Buy amount max slippage" }),
514
+ fees: optional(FeesSchema),
678
515
  });
679
516
 
680
- const QuoteResponseRouteItem = z.object({
681
- providers: z.array(z.nativeEnum(ProviderName)),
682
- sellAsset: z.string({
683
- description: "Asset to sell",
684
- }),
685
- sellAmount: z.string({
686
- description: "Sell amount",
687
- }),
688
- buyAsset: z.string({
689
- description: "Asset to buy",
690
- }),
691
- expectedBuyAmount: z.string({
692
- description: "Expected Buy amount",
693
- }),
694
- expectedBuyAmountMaxSlippage: z.string({
695
- description: "Expected Buy amount max slippage",
696
- }),
697
- sourceAddress: z.string({
698
- description: "Source address",
699
- }),
700
- destinationAddress: z.string({
701
- description: "Destination address",
702
- }),
703
- targetAddress: z.optional(
704
- z.string({
705
- description: "Target address",
706
- }),
707
- ),
708
- inboundAddress: z.optional(
709
- z.string({
710
- description: "Inbound address",
711
- }),
712
- ),
713
- expiration: z.optional(
714
- z.string({
715
- description: "Expiration",
716
- }),
717
- ),
718
- memo: z.optional(
719
- z.string({
720
- description: "Memo",
721
- }),
722
- ),
517
+ const QuoteResponseRouteItem = object({
518
+ providers: array(nativeEnum(ProviderName)),
519
+ sellAsset: string({ description: "Asset to sell" }),
520
+ sellAmount: string({ description: "Sell amount" }),
521
+ buyAsset: string({ description: "Asset to buy" }),
522
+ expectedBuyAmount: string({ description: "Expected Buy amount" }),
523
+ expectedBuyAmountMaxSlippage: string({ description: "Expected Buy amount max slippage" }),
524
+ sourceAddress: string({ description: "Source address" }),
525
+ destinationAddress: string({ description: "Destination address" }),
526
+ targetAddress: optional(string({ description: "Target address" })),
527
+ inboundAddress: optional(string({ description: "Inbound address" })),
528
+ expiration: optional(string({ description: "Expiration" })),
529
+ memo: optional(string({ description: "Memo" })),
723
530
  fees: FeesSchema,
724
- txType: z.optional(z.nativeEnum(RouteQuoteTxType)),
725
- tx: z.optional(z.union([EVMTransactionSchema, CosmosTransactionSchema, z.string()])),
726
- estimatedTime: z.optional(EstimatedTimeSchema), // TODO remove optionality
727
- totalSlippageBps: z.number({
728
- description: "Total slippage in bps",
729
- }),
730
- legs: z.array(QuoteResponseRouteLegItem),
531
+ txType: optional(nativeEnum(RouteQuoteTxType)),
532
+ tx: optional(union([EVMTransactionSchema, CosmosTransactionSchema, string()])),
533
+ estimatedTime: optional(EstimatedTimeSchema),
534
+ totalSlippageBps: number({ description: "Total slippage in bps" }),
535
+ legs: array(QuoteResponseRouteLegItem),
731
536
  warnings: RouteQuoteWarningSchema,
732
537
  meta: RouteQuoteMetadataSchema,
733
538
  });
734
539
 
735
- export const QuoteResponseSchema = z.object({
736
- quoteId: z.string({
737
- description: "Quote ID",
738
- }),
739
- routes: z.array(QuoteResponseRouteItem),
740
- // in case of bad request or actual backend error, not bad quotes from providers
741
- error: z.optional(
742
- z.string({
743
- description: "Error message",
744
- }),
745
- ),
746
- // errors from providers
747
- providerErrors: z.optional(
748
- z.array(
749
- z.object({
750
- provider: z.nativeEnum(ProviderName).optional(),
751
- errorCode: z.optional(z.nativeEnum(ErrorCode)),
752
- message: z.optional(z.string()),
540
+ export const QuoteResponseSchema = object({
541
+ quoteId: string({ description: "Quote ID" }),
542
+ routes: array(QuoteResponseRouteItem),
543
+ error: optional(string({ description: "Error message" })),
544
+ providerErrors: optional(
545
+ array(
546
+ object({
547
+ provider: nativeEnum(ProviderName).optional(),
548
+ errorCode: optional(nativeEnum(ErrorCode)),
549
+ message: optional(string()),
753
550
  }),
754
551
  ),
755
552
  ),
@@ -759,14 +556,21 @@ export type QuoteResponse = z.infer<typeof QuoteResponseSchema>;
759
556
  export type QuoteResponseRoute = z.infer<typeof QuoteResponseRouteItem>;
760
557
  export type QuoteResponseRouteLeg = z.infer<typeof QuoteResponseRouteLegItem>;
761
558
 
762
- export const GasResponseSchema = z.array(
763
- z.object({
764
- id: z.number(),
765
- chainId: z.string(),
766
- value: z.string(),
767
- unit: z.string(),
768
- createdAt: z.string(),
769
- }),
559
+ export const GasResponseSchema = array(
560
+ object({ id: number(), chainId: string(), value: string(), unit: string(), createdAt: string() }),
770
561
  );
771
562
 
772
563
  export type GasResponse = z.infer<typeof GasResponseSchema>;
564
+
565
+ const BalanceResponseSchema = array(
566
+ object({
567
+ chain: nativeEnum(Chain),
568
+ decimal: number(),
569
+ ticker: string(),
570
+ symbol: string(),
571
+ value: string(),
572
+ identifier: string(),
573
+ }),
574
+ );
575
+
576
+ export type BalanceResponse = z.infer<typeof BalanceResponseSchema>;