@swapkit/helpers 1.2.4 → 1.3.0

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,5 +1,3 @@
1
- import { z } from "zod";
2
-
3
1
  export enum ErrorCode {
4
2
  unknownError = "unknownError",
5
3
  test_error = "test_error",
@@ -119,103 +117,6 @@ export enum WarningCodeEnum {
119
117
  highPriceImpact = "highPriceImpact",
120
118
  }
121
119
 
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
-
147
- export const EVMTransactionDetailsParamsSchema = z.array(
148
- z.union([
149
- z.string(),
150
- z.number(),
151
- z.array(z.string()),
152
- z
153
- .object({
154
- from: z.string(),
155
- value: z.string(),
156
- })
157
- .describe("Parameters to pass to the contract method"),
158
- ]),
159
- );
160
-
161
- export type EVMTransactionDetailsParams = z.infer<typeof EVMTransactionDetailsParamsSchema>;
162
-
163
- export const EVMTransactionDetailsSchema = z.object({
164
- contractAddress: z.string({
165
- description: "Address of the contract to interact with",
166
- }),
167
- contractMethod: z.string({
168
- description: "Name of the method to call",
169
- }),
170
- contractParams: EVMTransactionDetailsParamsSchema,
171
- // contractParamsStreaming: z.array(
172
- // z.string({
173
- // description:
174
- // "If making a streaming swap through THORChain, parameters to pass to the contract method",
175
- // }),
176
- // ),
177
- contractParamNames: z.array(
178
- z.string({
179
- description: "Names of the parameters to pass to the contract method",
180
- }),
181
- ),
182
- approvalToken: z.optional(
183
- z.string({
184
- description: "Address of the token to approve spending of",
185
- }),
186
- ),
187
- approvalSpender: z.optional(
188
- z.string({
189
- description: "Address of the spender to approve",
190
- }),
191
- ),
192
- });
193
-
194
- export type EVMTransactionDetails = z.infer<typeof EVMTransactionDetailsSchema>;
195
-
196
- export const EstimatedTimeSchema = z.object({
197
- inbound: z.optional(
198
- z.number({
199
- description: "Time to receive inbound asset in seconds",
200
- }),
201
- ),
202
- swap: z.optional(
203
- z.number({
204
- description: "Time to swap assets in seconds",
205
- }),
206
- ),
207
- outbound: z.optional(
208
- z.number({
209
- description: "Time to receive outbound asset in seconds",
210
- }),
211
- ),
212
- total: z.number({
213
- description: "Total time in seconds",
214
- }),
215
- });
216
-
217
- export type EstimatedTime = z.infer<typeof EstimatedTimeSchema>;
218
-
219
120
  export enum ProviderName {
220
121
  CHAINFLIP = "CHAINFLIP",
221
122
  TRADERJOE_V1 = "TRADERJOE_V1",
@@ -239,257 +140,3 @@ export enum FeeTypeEnum {
239
140
  AFFILIATE = "affiliate",
240
141
  TAX = "tax",
241
142
  }
242
-
243
- export const FeesSchema = z.array(
244
- z.object({
245
- type: z.nativeEnum(FeeTypeEnum),
246
- amount: z.string(),
247
- asset: z.string(),
248
- chain: z.string(),
249
- protocol: z.nativeEnum(ProviderName),
250
- }),
251
- );
252
-
253
- export type Fees = z.infer<typeof FeesSchema>;
254
-
255
- export const RouteLegSchema = z.object({
256
- sellAsset: z.string({
257
- description: "Asset to sell",
258
- }),
259
- buyAsset: z.string({
260
- description: "Asset to buy",
261
- }),
262
- provider: z.nativeEnum(ProviderName),
263
- sourceAddress: z.string({
264
- description: "Source address",
265
- }),
266
- destinationAddress: z.string({
267
- description: "Destination address",
268
- }),
269
- estimatedTime: EstimatedTimeSchema.optional(),
270
- affiliate: z
271
- .string({
272
- description: "Affiliate address",
273
- })
274
- .optional(),
275
- affiliateFee: z
276
- .number({
277
- description: "Affiliate fee",
278
- })
279
- .optional(),
280
- slipPercentage: z.number({
281
- description: "Slippage as a percentage",
282
- }),
283
- });
284
-
285
- export type RouteLeg = z.infer<typeof RouteLegSchema>;
286
-
287
- export const RouteLegWithoutAddressesSchema = RouteLegSchema.omit({
288
- sourceAddress: true,
289
- destinationAddress: true,
290
- slipPercentage: true,
291
- });
292
-
293
- export type RouteLegWithoutAddresses = z.infer<typeof RouteLegWithoutAddressesSchema>;
294
-
295
- export const RouteQuoteMetadataAssetSchema = z.object({
296
- name: z.string({
297
- description: "Asset name",
298
- }),
299
- price: z.number({
300
- description: "Price in USD",
301
- }),
302
- image: z.string({
303
- description: "Asset image",
304
- }),
305
- });
306
-
307
- export type RouteQuoteMetadataAsset = z.infer<typeof RouteQuoteMetadataAssetSchema>;
308
-
309
- export const RouteQuoteMetadataSchema = z.object({
310
- priceImpact: z.number({
311
- description: "Price impact",
312
- }),
313
- assets: z.optional(z.array(RouteQuoteMetadataAssetSchema)),
314
- });
315
-
316
- export const RouteQuoteWarningSchema = z.array(
317
- z.object({
318
- code: z.nativeEnum(WarningCodeEnum),
319
- display: z.string(),
320
- tooltip: z.string().optional(),
321
- }),
322
- );
323
-
324
- export type EVMTransaction = z.infer<typeof EVMTransactionSchema>;
325
-
326
- const QuoteResponseRouteLegItemDev = z.object({
327
- provider: z.nativeEnum(ProviderName),
328
- sellAsset: z.string({
329
- description: "Asset to sell",
330
- }),
331
- sellAmount: z.string({
332
- description: "Sell amount",
333
- }),
334
- buyAsset: z.string({
335
- description: "Asset to buy",
336
- }),
337
- buyAmount: z.string({
338
- description: "Buy amount",
339
- }),
340
- buyAmountMaxSlippage: z.string({
341
- description: "Buy amount max slippage",
342
- }),
343
- fees: z.optional(FeesSchema), // TODO remove optionality
344
- });
345
-
346
- const QuoteResponseRouteItemDev = z.object({
347
- providers: z.array(z.nativeEnum(ProviderName)),
348
- sellAsset: z.string({
349
- description: "Asset to sell",
350
- }),
351
- sellAmount: z.string({
352
- description: "Sell amount",
353
- }),
354
- buyAsset: z.string({
355
- description: "Asset to buy",
356
- }),
357
- expectedBuyAmount: z.string({
358
- description: "Expected Buy amount",
359
- }),
360
- expectedBuyAmountMaxSlippage: z.string({
361
- description: "Expected Buy amount max slippage",
362
- }),
363
- sourceAddress: z.string({
364
- description: "Source address",
365
- }),
366
- destinationAddress: z.string({
367
- description: "Destination address",
368
- }),
369
- targetAddress: z.optional(
370
- z.string({
371
- description: "Target address",
372
- }),
373
- ),
374
- expiration: z.optional(
375
- z.string({
376
- description: "Expiration",
377
- }),
378
- ),
379
- memo: z.optional(
380
- z.string({
381
- description: "Memo",
382
- }),
383
- ),
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
388
- totalSlippageBps: z.number({
389
- description: "Total slippage in bps",
390
- }),
391
- legs: z.array(QuoteResponseRouteLegItemDev),
392
- warnings: RouteQuoteWarningSchema,
393
- meta: RouteQuoteMetadataSchema,
394
- });
395
-
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>;
411
-
412
- const QuoteResponseRouteLegItem = z.object({
413
- provider: z.nativeEnum(ProviderName),
414
- sellAsset: z.string({
415
- description: "Asset to sell",
416
- }),
417
- sellAmount: z.string({
418
- description: "Sell amount",
419
- }),
420
- buyAsset: z.string({
421
- description: "Asset to buy",
422
- }),
423
- buyAmount: z.string({
424
- description: "Buy amount",
425
- }),
426
- buyAmountMaxSlippage: z.string({
427
- description: "Buy amount max slippage",
428
- }),
429
- fees: z.optional(FeesSchema), // TODO remove optionality
430
- });
431
-
432
- const QuoteResponseRouteItem = z.object({
433
- providers: z.array(z.nativeEnum(ProviderName)),
434
- sellAsset: z.string({
435
- description: "Asset to sell",
436
- }),
437
- sellAmount: z.string({
438
- description: "Sell amount",
439
- }),
440
- buyAsset: z.string({
441
- description: "Asset to buy",
442
- }),
443
- expectedBuyAmount: z.string({
444
- description: "Expected Buy amount",
445
- }),
446
- expectedBuyAmountMaxSlippage: z.string({
447
- description: "Expected Buy amount max slippage",
448
- }),
449
- sourceAddress: z.string({
450
- description: "Source address",
451
- }),
452
- destinationAddress: z.string({
453
- description: "Destination address",
454
- }),
455
- targetAddress: z.optional(
456
- z.string({
457
- description: "Target address",
458
- }),
459
- ),
460
- expiration: z.optional(
461
- z.string({
462
- description: "Expiration",
463
- }),
464
- ),
465
- memo: z.optional(
466
- z.string({
467
- description: "Memo",
468
- }),
469
- ),
470
- evmTransactionDetails: z.optional(EVMTransactionDetailsSchema),
471
- transaction: z.optional(z.unknown()), // Can take many forms depending on the chains
472
- estimatedTime: z.optional(EstimatedTimeSchema), // TODO remove optionality
473
- totalSlippageBps: z.number({
474
- description: "Total slippage in bps",
475
- }),
476
- legs: z.array(QuoteResponseRouteLegItem),
477
- warnings: RouteQuoteWarningSchema,
478
- meta: RouteQuoteMetadataSchema,
479
- });
480
-
481
- export const QuoteResponseSchema = z.object({
482
- quoteId: z.string({
483
- description: "Quote ID",
484
- }),
485
- routes: z.array(QuoteResponseRouteItem),
486
- error: z.optional(
487
- z.string({
488
- description: "Error message",
489
- }),
490
- ),
491
- });
492
-
493
- export type QuoteResponse = z.infer<typeof QuoteResponseSchema>;
494
- export type QuoteResponseRoute = z.infer<typeof QuoteResponseRouteItem>;
495
- export type QuoteResponseRouteLeg = z.infer<typeof QuoteResponseRouteLegItem>;
package/src/types/sdk.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import type { CovalentApiType, EthplorerApiType } from "@swapkit/toolbox-evm";
2
2
  import type { BlockchairApiType } from "@swapkit/toolbox-utxo";
3
- import { z } from "zod";
4
3
 
5
4
  import type { AssetValue } from "../modules/assetValue";
6
5
  import type { Chain, CosmosChain, UTXOChain } from "./chains";
7
- import { ProviderName, type QuoteResponseRoute } from "./quotes";
8
6
 
9
7
  type CovalentChains =
10
8
  | Chain.BinanceSmartChain
@@ -19,15 +17,15 @@ export type ChainApis = { [key in CovalentChains]?: CovalentApiType } & {
19
17
  [key in UTXOChain]?: BlockchairApiType;
20
18
  };
21
19
 
22
- export type GenericSwapParams = {
20
+ export type GenericSwapParams<T = unknown> = {
23
21
  buyAsset?: AssetValue;
24
22
  sellAsset?: AssetValue;
25
23
  recipient?: string;
26
24
  feeOptionKey?: FeeOption;
27
- route: QuoteResponseRoute;
25
+ route: T;
28
26
  };
29
27
 
30
- export type SwapParams<PluginNames = string, T = GenericSwapParams> = T & {
28
+ export type SwapParams<PluginNames = string, R = unknown> = GenericSwapParams<R> & {
31
29
  pluginName?: PluginNames;
32
30
  };
33
31
 
@@ -65,96 +63,3 @@ export enum MemoType {
65
63
  RUNEPOOL_DEPOSIT = "POOL+",
66
64
  RUNEPOOL_WITHDRAW = "POOL-",
67
65
  }
68
-
69
- export const QuoteRequestSchema = z
70
- .object({
71
- sellAsset: z.string({
72
- description: "Asset to sell",
73
- }),
74
- buyAsset: z.string({
75
- description: "Asset to buy",
76
- }),
77
- sellAmount: z
78
- .number({
79
- description: "Amount of asset to sell",
80
- })
81
- .refine((amount) => amount > 0, {
82
- message: "sellAmount must be greater than 0",
83
- path: ["sellAmount"],
84
- }),
85
- providers: z.optional(
86
- z.array(
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
- ),
100
- ),
101
- ),
102
- sourceAddress: z.optional(
103
- z.string({
104
- description: "Address to send asset from",
105
- }),
106
- ),
107
- destinationAddress: z.optional(
108
- z.string({
109
- description: "Address to send asset to",
110
- }),
111
- ),
112
- slippage: z.optional(
113
- z.number({
114
- description: "Slippage tolerance as a percentage. Default is 3%.",
115
- }),
116
- ),
117
- affiliate: z.optional(
118
- z.string({
119
- description: "Affiliate thorname",
120
- }),
121
- ),
122
- affiliateFee: z.optional(
123
- z
124
- .number({
125
- description: "Affiliate fee in basis points",
126
- })
127
- .refine(
128
- (fee) => {
129
- return fee === Math.floor(fee) && fee >= 0;
130
- },
131
- { message: "affiliateFee must be a positive integer", path: ["affiliateFee"] },
132
- ),
133
- ),
134
- allowSmartContractSender: z.optional(
135
- z.boolean({
136
- description: "Allow smart contract as sender",
137
- }),
138
- ),
139
- allowSmartContractReceiver: z.optional(
140
- z.boolean({
141
- description: "Allow smart contract as recipient",
142
- }),
143
- ),
144
- disableSecurityChecks: z.optional(
145
- z.boolean({
146
- description: "Disable security checks",
147
- }),
148
- ),
149
- includeTx: z.optional(
150
- z.boolean({
151
- description: "Set to true to include an transaction object (EVM only)",
152
- }),
153
- ),
154
- })
155
- .refine((data) => data.sellAsset !== data.buyAsset, {
156
- message: "Must be different",
157
- path: ["sellAsset", "buyAsset"],
158
- });
159
-
160
- export type QuoteRequest = z.infer<typeof QuoteRequestSchema>;
@@ -1,99 +0,0 @@
1
- export const erc20ABI = [
2
- { inputs: [], stateMutability: "nonpayable", type: "constructor" },
3
- {
4
- anonymous: false,
5
- inputs: [
6
- { indexed: true, internalType: "address", name: "owner", type: "address" },
7
- { indexed: true, internalType: "address", name: "spender", type: "address" },
8
- { indexed: false, internalType: "uint256", name: "value", type: "uint256" },
9
- ],
10
- name: "Approval",
11
- type: "event",
12
- },
13
- {
14
- anonymous: false,
15
- inputs: [
16
- { indexed: true, internalType: "address", name: "from", type: "address" },
17
- { indexed: true, internalType: "address", name: "to", type: "address" },
18
- { indexed: false, internalType: "uint256", name: "value", type: "uint256" },
19
- ],
20
- name: "Transfer",
21
- type: "event",
22
- },
23
- {
24
- inputs: [
25
- { internalType: "address", name: "", type: "address" },
26
- { internalType: "address", name: "", type: "address" },
27
- ],
28
- name: "allowance",
29
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
30
- stateMutability: "view",
31
- type: "function",
32
- },
33
- {
34
- inputs: [
35
- { internalType: "address", name: "spender", type: "address" },
36
- { internalType: "uint256", name: "value", type: "uint256" },
37
- ],
38
- name: "approve",
39
- outputs: [{ internalType: "bool", name: "success", type: "bool" }],
40
- stateMutability: "nonpayable",
41
- type: "function",
42
- },
43
- {
44
- inputs: [{ internalType: "address", name: "", type: "address" }],
45
- name: "balanceOf",
46
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
47
- stateMutability: "view",
48
- type: "function",
49
- },
50
- {
51
- inputs: [],
52
- name: "decimals",
53
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
54
- stateMutability: "view",
55
- type: "function",
56
- },
57
- {
58
- inputs: [],
59
- name: "name",
60
- outputs: [{ internalType: "string", name: "", type: "string" }],
61
- stateMutability: "view",
62
- type: "function",
63
- },
64
- {
65
- inputs: [],
66
- name: "symbol",
67
- outputs: [{ internalType: "string", name: "", type: "string" }],
68
- stateMutability: "view",
69
- type: "function",
70
- },
71
- {
72
- inputs: [],
73
- name: "totalSupply",
74
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
75
- stateMutability: "view",
76
- type: "function",
77
- },
78
- {
79
- inputs: [
80
- { internalType: "address", name: "to", type: "address" },
81
- { internalType: "uint256", name: "value", type: "uint256" },
82
- ],
83
- name: "transfer",
84
- outputs: [{ internalType: "bool", name: "success", type: "bool" }],
85
- stateMutability: "nonpayable",
86
- type: "function",
87
- },
88
- {
89
- inputs: [
90
- { internalType: "address", name: "from", type: "address" },
91
- { internalType: "address", name: "to", type: "address" },
92
- { internalType: "uint256", name: "value", type: "uint256" },
93
- ],
94
- name: "transferFrom",
95
- outputs: [{ internalType: "bool", name: "success", type: "bool" }],
96
- stateMutability: "nonpayable",
97
- type: "function",
98
- },
99
- ];