@swapkit/helpers 1.0.0-rc.101 → 1.0.0-rc.103

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 CHANGED
@@ -1263,6 +1263,7 @@ var LedgerErrorCode;
1263
1263
  LedgerErrorCode2[LedgerErrorCode2["TC_NotFound"] = 65535] = "TC_NotFound";
1264
1264
  })(LedgerErrorCode || (LedgerErrorCode = {}));
1265
1265
  // src/types/sdk.ts
1266
+ import {z} from "zod";
1266
1267
  var FeeOption;
1267
1268
  (function(FeeOption2) {
1268
1269
  FeeOption2["Average"] = "average";
@@ -1285,6 +1286,347 @@ var MemoType;
1285
1286
  MemoType2["OPEN_LOAN"] = "$+";
1286
1287
  MemoType2["CLOSE_LOAN"] = "$-";
1287
1288
  })(MemoType || (MemoType = {}));
1289
+ var QuoteRequestSchema = z.object({
1290
+ sellAsset: z.string({
1291
+ description: "Asset to sell"
1292
+ }),
1293
+ buyAsset: z.string({
1294
+ description: "Asset to buy"
1295
+ }),
1296
+ sellAmount: z.number({
1297
+ description: "Amount of asset to sell"
1298
+ }).refine((amount) => amount > 0, {
1299
+ message: "sellAmount must be greater than 0",
1300
+ path: ["sellAmount"]
1301
+ }),
1302
+ providers: z.optional(z.array(z.string({
1303
+ description: "List of providers to use"
1304
+ }))),
1305
+ sourceAddress: z.optional(z.string({
1306
+ description: "Address to send asset from"
1307
+ })),
1308
+ destinationAddress: z.optional(z.string({
1309
+ description: "Address to send asset to"
1310
+ })),
1311
+ slippage: z.optional(z.number({
1312
+ description: "Slippage tolerance as a percentage. Default is 3%."
1313
+ })),
1314
+ affiliate: z.optional(z.string({
1315
+ description: "Affiliate thorname"
1316
+ })),
1317
+ affiliateFee: z.optional(z.number({
1318
+ description: "Affiliate fee in basis points"
1319
+ }).refine((fee) => {
1320
+ return fee === Math.floor(fee) && fee >= 0;
1321
+ }, { message: "affiliateFee must be a positive integer", path: ["affiliateFee"] })),
1322
+ allowSmartContractSender: z.optional(z.boolean({
1323
+ description: "Allow smart contract as sender"
1324
+ })),
1325
+ allowSmartContractReceiver: z.optional(z.boolean({
1326
+ description: "Allow smart contract as recipient"
1327
+ })),
1328
+ disableSecurityChecks: z.optional(z.boolean({
1329
+ description: "Disable security checks"
1330
+ }))
1331
+ }).refine((data) => data.sellAsset !== data.buyAsset, {
1332
+ message: "Must be different",
1333
+ path: ["sellAsset", "buyAsset"]
1334
+ });
1335
+ // src/types/quotes.ts
1336
+ import {z as z2} from "zod";
1337
+ var WarningCodeEnum;
1338
+ (function(WarningCodeEnum2) {
1339
+ WarningCodeEnum2["highSlippage"] = "highSlippage";
1340
+ WarningCodeEnum2["highPriceImpact"] = "highPriceImpact";
1341
+ })(WarningCodeEnum || (WarningCodeEnum = {}));
1342
+ var EVMTransactionDetailsParamsSchema = z2.array(z2.union([
1343
+ z2.string(),
1344
+ z2.number(),
1345
+ z2.array(z2.string()),
1346
+ z2.object({
1347
+ from: z2.string(),
1348
+ value: z2.string()
1349
+ }).describe("Parameters to pass to the contract method")
1350
+ ]));
1351
+ var EVMTransactionDetailsSchema = z2.object({
1352
+ contractAddress: z2.string({
1353
+ description: "Address of the contract to interact with"
1354
+ }),
1355
+ contractMethod: z2.string({
1356
+ description: "Name of the method to call"
1357
+ }),
1358
+ contractParams: EVMTransactionDetailsParamsSchema,
1359
+ contractParamNames: z2.array(z2.string({
1360
+ description: "Names of the parameters to pass to the contract method"
1361
+ })),
1362
+ approvalToken: z2.optional(z2.string({
1363
+ description: "Address of the token to approve spending of"
1364
+ })),
1365
+ approvalSpender: z2.optional(z2.string({
1366
+ description: "Address of the spender to approve"
1367
+ }))
1368
+ });
1369
+ var EstimatedTimeSchema = z2.object({
1370
+ inbound: z2.optional(z2.number({
1371
+ description: "Time to receive inbound asset in seconds"
1372
+ })),
1373
+ swap: z2.optional(z2.number({
1374
+ description: "Time to swap assets in seconds"
1375
+ })),
1376
+ outbound: z2.optional(z2.number({
1377
+ description: "Time to receive outbound asset in seconds"
1378
+ })),
1379
+ total: z2.number({
1380
+ description: "Total time in seconds"
1381
+ })
1382
+ });
1383
+ var ProviderName;
1384
+ (function(ProviderName2) {
1385
+ ProviderName2["CHAINFLIP"] = "CHAINFLIP";
1386
+ ProviderName2["TRADERJOE_V1"] = "TRADERJOE_V1";
1387
+ ProviderName2["PANGOLIN_V1"] = "PANGOLIN_V1";
1388
+ ProviderName2["UNISWAP_V2"] = "UNISWAP_V2";
1389
+ ProviderName2["THORCHAIN"] = "THORCHAIN";
1390
+ ProviderName2["THORCHAIN_STREAMING"] = "THORCHAIN_STREAMING";
1391
+ ProviderName2["MAYACHAIN"] = "MAYACHAIN";
1392
+ ProviderName2["ONEINCH"] = "ONEINCH";
1393
+ ProviderName2["SUSHISWAP_V2"] = "SUSHISWAP_V2";
1394
+ ProviderName2["WOOFI_V2"] = "WOOFI_V2";
1395
+ ProviderName2["PANCAKESWAP"] = "PANCAKESWAP";
1396
+ })(ProviderName || (ProviderName = {}));
1397
+ var FeeTypeEnum;
1398
+ (function(FeeTypeEnum2) {
1399
+ FeeTypeEnum2["LIQUIDITY"] = "liquidity";
1400
+ FeeTypeEnum2["NETWORK"] = "network";
1401
+ FeeTypeEnum2["INBOUND"] = "inbound";
1402
+ FeeTypeEnum2["OUTBOUND"] = "outbound";
1403
+ FeeTypeEnum2["AFFILIATE"] = "affiliate";
1404
+ FeeTypeEnum2["TAX"] = "tax";
1405
+ })(FeeTypeEnum || (FeeTypeEnum = {}));
1406
+ var FeesSchema = z2.array(z2.object({
1407
+ type: z2.nativeEnum(FeeTypeEnum),
1408
+ amount: z2.string(),
1409
+ asset: z2.string(),
1410
+ chain: z2.string(),
1411
+ protocol: z2.nativeEnum(ProviderName)
1412
+ }));
1413
+ var RouteLegSchema = z2.object({
1414
+ sellAsset: z2.string({
1415
+ description: "Asset to sell"
1416
+ }),
1417
+ buyAsset: z2.string({
1418
+ description: "Asset to buy"
1419
+ }),
1420
+ provider: z2.nativeEnum(ProviderName),
1421
+ sourceAddress: z2.string({
1422
+ description: "Source address"
1423
+ }),
1424
+ destinationAddress: z2.string({
1425
+ description: "Destination address"
1426
+ }),
1427
+ estimatedTime: EstimatedTimeSchema.optional(),
1428
+ affiliate: z2.string({
1429
+ description: "Affiliate address"
1430
+ }).optional(),
1431
+ affiliateFee: z2.number({
1432
+ description: "Affiliate fee"
1433
+ }).optional(),
1434
+ slipPercentage: z2.number({
1435
+ description: "Slippage as a percentage"
1436
+ })
1437
+ });
1438
+ var RouteLegWithoutAddressesSchema = RouteLegSchema.omit({
1439
+ sourceAddress: true,
1440
+ destinationAddress: true,
1441
+ slipPercentage: true
1442
+ });
1443
+ var RouteQuoteMetadataAssetSchema = z2.object({
1444
+ name: z2.string({
1445
+ description: "Asset name"
1446
+ }),
1447
+ price: z2.number({
1448
+ description: "Price in USD"
1449
+ }),
1450
+ image: z2.string({
1451
+ description: "Asset image"
1452
+ })
1453
+ });
1454
+ var RouteQuoteMetadataSchema = z2.object({
1455
+ priceImpact: z2.number({
1456
+ description: "Price impact"
1457
+ }),
1458
+ assets: z2.optional(z2.array(RouteQuoteMetadataAssetSchema))
1459
+ });
1460
+ var RouteQuoteWarningSchema = z2.array(z2.object({
1461
+ code: z2.nativeEnum(WarningCodeEnum),
1462
+ display: z2.string(),
1463
+ tooltip: z2.string().optional()
1464
+ }));
1465
+ var RouteQuoteLegSchema = z2.object({
1466
+ sellAsset: z2.string({
1467
+ description: "Asset to sell"
1468
+ }),
1469
+ buyAsset: z2.string({
1470
+ description: "Asset to buy"
1471
+ }),
1472
+ provider: z2.nativeEnum(ProviderName),
1473
+ buyAmount: z2.string({
1474
+ description: "Amount of asset to buy"
1475
+ }),
1476
+ buyAmountMaxSlippage: z2.string({
1477
+ description: "Amount of asset to buy"
1478
+ }),
1479
+ sellAmount: z2.string({
1480
+ description: "Amount of asset to sell"
1481
+ }),
1482
+ sourceAddress: z2.string({
1483
+ description: "Source address"
1484
+ }),
1485
+ destinationAddress: z2.string({
1486
+ description: "Destination address"
1487
+ }),
1488
+ slippageBps: z2.number({
1489
+ description: "Slippage in bps"
1490
+ }),
1491
+ targetAddress: z2.optional(z2.string({
1492
+ description: "Target address for contract call or transfer address"
1493
+ })),
1494
+ inboundAddress: z2.optional(z2.string({
1495
+ description: "Inbound address"
1496
+ })),
1497
+ routerAddress: z2.optional(z2.string({
1498
+ description: "Inbound address"
1499
+ })),
1500
+ contractMethod: z2.optional(z2.string({
1501
+ description: "Contract method"
1502
+ })),
1503
+ fees: z2.optional(FeesSchema),
1504
+ estimatedTime: z2.optional(EstimatedTimeSchema),
1505
+ memo: z2.optional(z2.string({
1506
+ description: "Memo"
1507
+ })),
1508
+ expiration: z2.optional(z2.string({
1509
+ description: "Expiration"
1510
+ }))
1511
+ });
1512
+ var RouteQuoteSchema = z2.object({
1513
+ providers: z2.array(z2.nativeEnum(ProviderName)),
1514
+ sellAsset: z2.string({
1515
+ description: "Asset to sell"
1516
+ }),
1517
+ sellAmount: z2.string({
1518
+ description: "sell amount"
1519
+ }),
1520
+ buyAsset: z2.string({
1521
+ description: "Asset to buy"
1522
+ }),
1523
+ expectedBuyAmount: z2.string({
1524
+ description: "Expected Buy amount"
1525
+ }),
1526
+ expectedBuyAmountMaxSlippage: z2.string({
1527
+ description: "Expected Buy amount max slippage"
1528
+ }),
1529
+ sourceAddress: z2.string({
1530
+ description: "Source address"
1531
+ }),
1532
+ destinationAddress: z2.string({
1533
+ description: "Destination address"
1534
+ }),
1535
+ targetAddress: z2.optional(z2.string({
1536
+ description: "Target address"
1537
+ })),
1538
+ routerAddress: z2.optional(z2.string({
1539
+ description: "Router address"
1540
+ })),
1541
+ inboundAddress: z2.optional(z2.string({
1542
+ description: "Inbound address"
1543
+ })),
1544
+ expiration: z2.optional(z2.string({
1545
+ description: "Expiration"
1546
+ })),
1547
+ memo: z2.optional(z2.string({
1548
+ description: "Memo"
1549
+ })),
1550
+ evmTransactionDetails: z2.optional(EVMTransactionDetailsSchema),
1551
+ routePathArray: z2.optional(z2.array(z2.string())),
1552
+ estimatedTime: z2.optional(EstimatedTimeSchema),
1553
+ totalSlippageBps: z2.number({
1554
+ description: "Total slippage in bps"
1555
+ }),
1556
+ legs: z2.array(RouteQuoteLegSchema),
1557
+ errorCode: z2.optional(z2.string()),
1558
+ warnings: RouteQuoteWarningSchema,
1559
+ meta: RouteQuoteMetadataSchema
1560
+ });
1561
+ var QuoteResponseRouteLegItem = z2.object({
1562
+ provider: z2.nativeEnum(ProviderName),
1563
+ sellAsset: z2.string({
1564
+ description: "Asset to sell"
1565
+ }),
1566
+ sellAmount: z2.string({
1567
+ description: "Sell amount"
1568
+ }),
1569
+ buyAsset: z2.string({
1570
+ description: "Asset to buy"
1571
+ }),
1572
+ buyAmount: z2.string({
1573
+ description: "Buy amount"
1574
+ }),
1575
+ buyAmountMaxSlippage: z2.string({
1576
+ description: "Buy amount max slippage"
1577
+ }),
1578
+ fees: z2.optional(FeesSchema)
1579
+ });
1580
+ var QuoteResponseRouteItem = z2.object({
1581
+ providers: z2.array(z2.nativeEnum(ProviderName)),
1582
+ sellAsset: z2.string({
1583
+ description: "Asset to sell"
1584
+ }),
1585
+ sellAmount: z2.string({
1586
+ description: "sell amount"
1587
+ }),
1588
+ buyAsset: z2.string({
1589
+ description: "Asset to buy"
1590
+ }),
1591
+ expectedBuyAmount: z2.string({
1592
+ description: "Expected Buy amount"
1593
+ }),
1594
+ expectedBuyAmountMaxSlippage: z2.string({
1595
+ description: "Expected Buy amount max slippage"
1596
+ }),
1597
+ sourceAddress: z2.string({
1598
+ description: "Source address"
1599
+ }),
1600
+ destinationAddress: z2.string({
1601
+ description: "Destination address"
1602
+ }),
1603
+ targetAddress: z2.optional(z2.string({
1604
+ description: "Target address"
1605
+ })),
1606
+ expiration: z2.optional(z2.string({
1607
+ description: "Expiration"
1608
+ })),
1609
+ memo: z2.optional(z2.string({
1610
+ description: "Memo"
1611
+ })),
1612
+ evmTransactionDetails: z2.optional(EVMTransactionDetailsSchema),
1613
+ estimatedTime: z2.optional(EstimatedTimeSchema),
1614
+ totalSlippageBps: z2.number({
1615
+ description: "Total slippage in bps"
1616
+ }),
1617
+ legs: z2.array(QuoteResponseRouteLegItem),
1618
+ warnings: RouteQuoteWarningSchema,
1619
+ meta: RouteQuoteMetadataSchema
1620
+ });
1621
+ var QuoteResponseSchema = z2.object({
1622
+ quoteId: z2.string({
1623
+ description: "Quote ID"
1624
+ }),
1625
+ routes: z2.array(QuoteResponseRouteItem),
1626
+ error: z2.optional(z2.string({
1627
+ description: "Error message"
1628
+ }))
1629
+ });
1288
1630
  // src/modules/requestClient.ts
1289
1631
  import ky from "ky";
1290
1632
  function setRequestClientConfig({ apiKey, ...config }) {
@@ -1301,9 +1643,9 @@ var getKyClient = function() {
1301
1643
  };
1302
1644
  var kyClient;
1303
1645
  var defaultRequestHeaders = typeof window !== "undefined" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" };
1304
- var getTypedBaseRequestClient = (kyClient2) => ({
1305
- get: (url, options) => kyClient2.get(url, options).json(),
1306
- post: (url, options) => kyClient2.post(url, options).json()
1646
+ var getTypedBaseRequestClient = (ky2) => ({
1647
+ get: (url, options) => ky2.get(url, options).json(),
1648
+ post: (url, options) => ky2.post(url, options).json()
1307
1649
  });
1308
1650
  var RequestClient = {
1309
1651
  ...getTypedBaseRequestClient(getKyClient()),
@@ -1726,6 +2068,7 @@ var errorMessages = {
1726
2068
  wallet_ledger_device_locked: 20005,
1727
2069
  chainflip_channel_error: 30001,
1728
2070
  chainflip_broker_recipient_error: 30002,
2071
+ api_v2_invalid_response: 40001,
1729
2072
  helpers_number_different_decimals: 99101
1730
2073
  };
1731
2074
 
@@ -2427,6 +2770,7 @@ export {
2427
2770
  assetFromString,
2428
2771
  addEVMWalletNetwork,
2429
2772
  addAccountsChangedCallback,
2773
+ WarningCodeEnum,
2430
2774
  WalletOption,
2431
2775
  UTXOChains,
2432
2776
  TCSupportedChains,
@@ -2438,17 +2782,32 @@ export {
2438
2782
  SubstrateChains,
2439
2783
  SWAP_OUT,
2440
2784
  SWAP_IN,
2785
+ RouteQuoteWarningSchema,
2786
+ RouteQuoteSchema,
2787
+ RouteQuoteMetadataSchema,
2788
+ RouteQuoteMetadataAssetSchema,
2789
+ RouteQuoteLegSchema,
2790
+ RouteLegWithoutAddressesSchema,
2791
+ RouteLegSchema,
2441
2792
  RequestClient,
2442
2793
  RPCUrl,
2794
+ QuoteResponseSchema,
2795
+ QuoteRequestSchema,
2443
2796
  QuoteMode,
2797
+ ProviderName,
2444
2798
  NetworkDerivationPath,
2445
2799
  MemoType,
2446
2800
  MayaEthereumVaultAbi,
2447
2801
  MayaArbitrumVaultAbi,
2448
2802
  MAYASupportedChains,
2449
2803
  LedgerErrorCode,
2804
+ FeesSchema,
2805
+ FeeTypeEnum,
2450
2806
  FeeOption,
2451
2807
  ExplorerUrl,
2808
+ EstimatedTimeSchema,
2809
+ EVMTransactionDetailsSchema,
2810
+ EVMTransactionDetailsParamsSchema,
2452
2811
  EVMChains,
2453
2812
  DerivationPath,
2454
2813
  CosmosChains,
@@ -2467,4 +2826,4 @@ export {
2467
2826
  AGG_SWAP
2468
2827
  };
2469
2828
 
2470
- //# debugId=7D694DE433F7244B64756e2164756e21
2829
+ //# debugId=1AF616D9C1303CD064756e2164756e21