@rhea-finance/cross-chain-sdk 0.1.7 → 0.1.9

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/README.md CHANGED
@@ -759,6 +759,33 @@ if (relayer_result?.code == 0) {
759
759
  }
760
760
  ```
761
761
 
762
+ ### Get farm details for an asset
763
+
764
+ ```typescript
765
+ import {
766
+ getFarmDetailsOfAsset,
767
+ getAssetDetailsView,
768
+ } from "@rhea-finance/cross-chain-sdk";
769
+
770
+ // Get assets view (IAssetsView)
771
+ const assets = await getAssetDetailsView();
772
+
773
+ // Get farm details for a specific asset
774
+ const farmDetails = getFarmDetailsOfAsset({
775
+ assets,
776
+ assetId: "zec.omft.near",
777
+ booster: 1.5, // optional, default 1.5
778
+ });
779
+
780
+ // farmDetails: IFarmDetailsOfAsset
781
+ console.log(farmDetails.minFarmApy); // market farm APY (min)
782
+ console.log(farmDetails.maxFarmApy); // max farm APY (with booster)
783
+ console.log(farmDetails.tokenNetRewards); // reward token metadata
784
+ console.log(farmDetails.canBeBooster); // whether asset can be boosted
785
+ console.log(farmDetails.supplyApy); // supply APR (%)
786
+ console.log(farmDetails.borrowApy); // borrow APR (%)
787
+ ```
788
+
762
789
  ### Cross-chain Withdraw Rewards
763
790
 
764
791
  ```typescript
@@ -882,6 +909,7 @@ if (res.status === "success") {
882
909
  - `getPrices` - Get price information
883
910
  - `getBalance` - Get balance
884
911
  - `getFarms` - Get liquidity mining information
912
+ - `getFarmDetailsOfAsset` - Get farm details (APY, rewards, canBeBooster) for an asset
885
913
  - `getConfig` - Get configuration
886
914
  - `getBoosterTokens` - Get booster token information
887
915
  - `getTokenDetail` - Get token details
package/dist/index.cjs CHANGED
@@ -18294,7 +18294,7 @@ async function postMultichainLendingRequests({
18294
18294
  mca_id,
18295
18295
  wallet,
18296
18296
  request,
18297
- page_display_data
18297
+ page_display_data = ""
18298
18298
  }) {
18299
18299
  try {
18300
18300
  const params = {
@@ -20071,6 +20071,59 @@ var getAllFarms = async () => {
20071
20071
  throw new Error("getAllFarms");
20072
20072
  }
20073
20073
  };
20074
+ function getFarmDetailsOfAsset({
20075
+ assets,
20076
+ assetId,
20077
+ booster = 1.5
20078
+ }) {
20079
+ const asset = assets[assetId];
20080
+ if (!asset) {
20081
+ return {
20082
+ minFarmApy: 0,
20083
+ maxFarmApy: 0,
20084
+ tokenNetRewards: [],
20085
+ canBeBooster: false,
20086
+ supplyApy: 0,
20087
+ borrowApy: 0
20088
+ };
20089
+ }
20090
+ const tokenNetFarms = asset.farms.tokennetbalance || {};
20091
+ const assetDecimals = (asset.metadata?.decimals ?? 0) + (asset.config?.extra_decimals ?? 0);
20092
+ const rewardMetas = [];
20093
+ for (const rewardTokenId of Object.keys(tokenNetFarms)) {
20094
+ const rewardAsset = assets[rewardTokenId];
20095
+ if (rewardAsset?.metadata) rewardMetas.push(rewardAsset.metadata);
20096
+ }
20097
+ const firstFarm = Object.values(tokenNetFarms)[0];
20098
+ const canBeBooster = !!(firstFarm?.booster_log_bases && Object.keys(firstFarm.booster_log_bases).length > 0);
20099
+ const marketFarmApy = Object.entries(tokenNetFarms).reduce(
20100
+ (acc, [rewardTokenId, farmData]) => {
20101
+ const rewardAsset = assets[rewardTokenId];
20102
+ if (!rewardAsset) return acc;
20103
+ const rewardAPY = new Decimal13__default.default(farmData.reward_per_day).div(
20104
+ new Decimal13__default.default(10).pow(
20105
+ (rewardAsset.metadata?.decimals ?? 0) + (rewardAsset.config?.extra_decimals ?? 0)
20106
+ )
20107
+ ).mul(365).mul(rewardAsset.price?.usd || "0").div(
20108
+ new Decimal13__default.default(shrinkToken(farmData.boosted_shares, assetDecimals)).mul(
20109
+ asset.price?.usd || "0"
20110
+ )
20111
+ ).mul(100);
20112
+ return acc.plus(rewardAPY);
20113
+ },
20114
+ new Decimal13__default.default(0)
20115
+ );
20116
+ const supplyApr = new Decimal13__default.default(asset.supply_apr || 0).mul(100).toNumber();
20117
+ const borrowApr = new Decimal13__default.default(asset.borrow_apr || 0).mul(100).toNumber();
20118
+ return {
20119
+ minFarmApy: marketFarmApy.toNumber(),
20120
+ maxFarmApy: marketFarmApy.mul(booster).toNumber(),
20121
+ supplyApy: supplyApr,
20122
+ borrowApy: borrowApr,
20123
+ tokenNetRewards: rewardMetas,
20124
+ canBeBooster
20125
+ };
20126
+ }
20074
20127
 
20075
20128
  // src/view/zcash.ts
20076
20129
  init_polyfills();
@@ -21079,6 +21132,7 @@ exports.getConfig = getConfig2;
21079
21132
  exports.getCreateMcaCustomRecipientMsg = getCreateMcaCustomRecipientMsg;
21080
21133
  exports.getCreateMcaFee = getCreateMcaFee;
21081
21134
  exports.getCreateMcaFeePaged = getCreateMcaFeePaged;
21135
+ exports.getFarmDetailsOfAsset = getFarmDetailsOfAsset;
21082
21136
  exports.getListWalletsByMca = getListWalletsByMca;
21083
21137
  exports.getMcaByWallet = getMcaByWallet;
21084
21138
  exports.getMultichainLendingConfig = getMultichainLendingConfig;