@zyfai/sdk 0.2.1 → 0.2.2

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
@@ -637,6 +637,35 @@ function toInternalStrategy(publicStrategy) {
637
637
  );
638
638
  }
639
639
  }
640
+ function toPublicStrategy(internalStrategy) {
641
+ if (internalStrategy === "safe_strategy" || internalStrategy === "safe") {
642
+ return "conservative";
643
+ }
644
+ if (internalStrategy === "degen_strategy" || internalStrategy === "degen") {
645
+ return "aggressive";
646
+ }
647
+ throw new Error(
648
+ `Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy" or "degen_strategy".`
649
+ );
650
+ }
651
+ function convertStrategyToPublic(obj) {
652
+ if (!obj.strategy) {
653
+ return obj;
654
+ }
655
+ try {
656
+ return {
657
+ ...obj,
658
+ strategy: toPublicStrategy(
659
+ obj.strategy
660
+ )
661
+ };
662
+ } catch {
663
+ return obj;
664
+ }
665
+ }
666
+ function convertStrategiesToPublic(array) {
667
+ return array.map((item) => convertStrategyToPublic(item));
668
+ }
640
669
 
641
670
  // src/core/ZyfaiSDK.ts
642
671
  var import_siwe = require("siwe");
@@ -1538,10 +1567,11 @@ var ZyfaiSDK = class {
1538
1567
  const response = await this.httpClient.get(
1539
1568
  ENDPOINTS.DATA_POSITION(smartWalletInfo.smartWallet)
1540
1569
  );
1570
+ const convertedPositions = response ? [convertStrategyToPublic(response)] : [];
1541
1571
  return {
1542
1572
  success: true,
1543
1573
  userAddress,
1544
- positions: response ? [response] : []
1574
+ positions: convertedPositions
1545
1575
  };
1546
1576
  } catch (error) {
1547
1577
  throw new Error(`Failed to get positions: ${error.message}`);
@@ -1568,25 +1598,26 @@ var ZyfaiSDK = class {
1568
1598
  try {
1569
1599
  await this.authenticateUser();
1570
1600
  const response = await this.httpClient.get(ENDPOINTS.USER_ME);
1601
+ const convertedResponse = convertStrategyToPublic(response);
1571
1602
  return {
1572
1603
  success: true,
1573
1604
  user: {
1574
- id: response.id,
1575
- address: response.address,
1576
- smartWallet: response.smartWallet,
1577
- chains: response.chains || [],
1578
- protocols: response.protocols || [],
1579
- hasActiveSessionKey: response.hasActiveSessionKey || false,
1580
- email: response.email,
1581
- strategy: response.strategy,
1582
- telegramId: response.telegramId,
1583
- walletType: response.walletType,
1584
- autoSelectProtocols: response.autoSelectProtocols || false,
1585
- autocompounding: response.autocompounding,
1586
- omniAccount: response.omniAccount,
1587
- crosschainStrategy: response.crosschainStrategy,
1588
- agentName: response.agentName,
1589
- customization: response.customization
1605
+ id: convertedResponse.id,
1606
+ address: convertedResponse.address,
1607
+ smartWallet: convertedResponse.smartWallet,
1608
+ chains: convertedResponse.chains || [],
1609
+ protocols: convertedResponse.protocols || [],
1610
+ hasActiveSessionKey: convertedResponse.hasActiveSessionKey || false,
1611
+ email: convertedResponse.email,
1612
+ strategy: convertedResponse.strategy,
1613
+ telegramId: convertedResponse.telegramId,
1614
+ walletType: convertedResponse.walletType,
1615
+ autoSelectProtocols: convertedResponse.autoSelectProtocols || false,
1616
+ autocompounding: convertedResponse.autocompounding,
1617
+ omniAccount: convertedResponse.omniAccount,
1618
+ crosschainStrategy: convertedResponse.crosschainStrategy,
1619
+ agentName: convertedResponse.agentName,
1620
+ customization: convertedResponse.customization
1590
1621
  }
1591
1622
  };
1592
1623
  } catch (error) {
@@ -1653,10 +1684,13 @@ var ZyfaiSDK = class {
1653
1684
  const response = await this.httpClient.dataGet(
1654
1685
  DATA_ENDPOINTS.APY_PER_STRATEGY(crossChain, days, internalStrategyShort)
1655
1686
  );
1687
+ const convertedData = convertStrategiesToPublic(
1688
+ response.data || []
1689
+ );
1656
1690
  return {
1657
1691
  success: true,
1658
1692
  count: response.count || 0,
1659
- data: response.data || []
1693
+ data: convertedData
1660
1694
  };
1661
1695
  } catch (error) {
1662
1696
  throw new Error(
@@ -1826,10 +1860,11 @@ var ZyfaiSDK = class {
1826
1860
  if (options?.fromDate) endpoint += `&fromDate=${options.fromDate}`;
1827
1861
  if (options?.toDate) endpoint += `&toDate=${options.toDate}`;
1828
1862
  const response = await this.httpClient.get(endpoint);
1863
+ const convertedData = convertStrategiesToPublic(response.data || []);
1829
1864
  return {
1830
1865
  success: true,
1831
1866
  walletAddress,
1832
- data: response.data || [],
1867
+ data: convertedData,
1833
1868
  total: response.total || 0
1834
1869
  };
1835
1870
  } catch (error) {
package/dist/index.mjs CHANGED
@@ -614,6 +614,35 @@ function toInternalStrategy(publicStrategy) {
614
614
  );
615
615
  }
616
616
  }
617
+ function toPublicStrategy(internalStrategy) {
618
+ if (internalStrategy === "safe_strategy" || internalStrategy === "safe") {
619
+ return "conservative";
620
+ }
621
+ if (internalStrategy === "degen_strategy" || internalStrategy === "degen") {
622
+ return "aggressive";
623
+ }
624
+ throw new Error(
625
+ `Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy" or "degen_strategy".`
626
+ );
627
+ }
628
+ function convertStrategyToPublic(obj) {
629
+ if (!obj.strategy) {
630
+ return obj;
631
+ }
632
+ try {
633
+ return {
634
+ ...obj,
635
+ strategy: toPublicStrategy(
636
+ obj.strategy
637
+ )
638
+ };
639
+ } catch {
640
+ return obj;
641
+ }
642
+ }
643
+ function convertStrategiesToPublic(array) {
644
+ return array.map((item) => convertStrategyToPublic(item));
645
+ }
617
646
 
618
647
  // src/core/ZyfaiSDK.ts
619
648
  import { SiweMessage } from "siwe";
@@ -1515,10 +1544,11 @@ var ZyfaiSDK = class {
1515
1544
  const response = await this.httpClient.get(
1516
1545
  ENDPOINTS.DATA_POSITION(smartWalletInfo.smartWallet)
1517
1546
  );
1547
+ const convertedPositions = response ? [convertStrategyToPublic(response)] : [];
1518
1548
  return {
1519
1549
  success: true,
1520
1550
  userAddress,
1521
- positions: response ? [response] : []
1551
+ positions: convertedPositions
1522
1552
  };
1523
1553
  } catch (error) {
1524
1554
  throw new Error(`Failed to get positions: ${error.message}`);
@@ -1545,25 +1575,26 @@ var ZyfaiSDK = class {
1545
1575
  try {
1546
1576
  await this.authenticateUser();
1547
1577
  const response = await this.httpClient.get(ENDPOINTS.USER_ME);
1578
+ const convertedResponse = convertStrategyToPublic(response);
1548
1579
  return {
1549
1580
  success: true,
1550
1581
  user: {
1551
- id: response.id,
1552
- address: response.address,
1553
- smartWallet: response.smartWallet,
1554
- chains: response.chains || [],
1555
- protocols: response.protocols || [],
1556
- hasActiveSessionKey: response.hasActiveSessionKey || false,
1557
- email: response.email,
1558
- strategy: response.strategy,
1559
- telegramId: response.telegramId,
1560
- walletType: response.walletType,
1561
- autoSelectProtocols: response.autoSelectProtocols || false,
1562
- autocompounding: response.autocompounding,
1563
- omniAccount: response.omniAccount,
1564
- crosschainStrategy: response.crosschainStrategy,
1565
- agentName: response.agentName,
1566
- customization: response.customization
1582
+ id: convertedResponse.id,
1583
+ address: convertedResponse.address,
1584
+ smartWallet: convertedResponse.smartWallet,
1585
+ chains: convertedResponse.chains || [],
1586
+ protocols: convertedResponse.protocols || [],
1587
+ hasActiveSessionKey: convertedResponse.hasActiveSessionKey || false,
1588
+ email: convertedResponse.email,
1589
+ strategy: convertedResponse.strategy,
1590
+ telegramId: convertedResponse.telegramId,
1591
+ walletType: convertedResponse.walletType,
1592
+ autoSelectProtocols: convertedResponse.autoSelectProtocols || false,
1593
+ autocompounding: convertedResponse.autocompounding,
1594
+ omniAccount: convertedResponse.omniAccount,
1595
+ crosschainStrategy: convertedResponse.crosschainStrategy,
1596
+ agentName: convertedResponse.agentName,
1597
+ customization: convertedResponse.customization
1567
1598
  }
1568
1599
  };
1569
1600
  } catch (error) {
@@ -1630,10 +1661,13 @@ var ZyfaiSDK = class {
1630
1661
  const response = await this.httpClient.dataGet(
1631
1662
  DATA_ENDPOINTS.APY_PER_STRATEGY(crossChain, days, internalStrategyShort)
1632
1663
  );
1664
+ const convertedData = convertStrategiesToPublic(
1665
+ response.data || []
1666
+ );
1633
1667
  return {
1634
1668
  success: true,
1635
1669
  count: response.count || 0,
1636
- data: response.data || []
1670
+ data: convertedData
1637
1671
  };
1638
1672
  } catch (error) {
1639
1673
  throw new Error(
@@ -1803,10 +1837,11 @@ var ZyfaiSDK = class {
1803
1837
  if (options?.fromDate) endpoint += `&fromDate=${options.fromDate}`;
1804
1838
  if (options?.toDate) endpoint += `&toDate=${options.toDate}`;
1805
1839
  const response = await this.httpClient.get(endpoint);
1840
+ const convertedData = convertStrategiesToPublic(response.data || []);
1806
1841
  return {
1807
1842
  success: true,
1808
1843
  walletAddress,
1809
- data: response.data || [],
1844
+ data: convertedData,
1810
1845
  total: response.total || 0
1811
1846
  };
1812
1847
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "TypeScript SDK for Zyfai Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",