carbon-js-sdk 0.2.14-dev.6 → 0.2.14-dev.7

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.
@@ -3,6 +3,7 @@ import { CarbonTx } from "../util";
3
3
  import { BigNumber } from "bignumber.js";
4
4
  import { Debt } from './../codec/cdp/query';
5
5
  import BaseModule from "./base";
6
+ import { Params } from '../codec/cdp/params';
6
7
  export declare class CDPModule extends BaseModule {
7
8
  private cdpModuleAddress;
8
9
  supplyAsset(params: CDPModule.SupplyAssetParams, opts?: CarbonTx.SignTxOpts): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
@@ -43,6 +44,7 @@ export declare class CDPModule extends BaseModule {
43
44
  getTotalAccountTokenDebt(account: string, denom: string, debt?: Debt, debtInfo?: DebtInfo): Promise<BigNumber>;
44
45
  getTotalAccountStablecoinDebt(account: string, debt?: CDPModule.StablecoinDebt, debtInfo?: StablecoinDebtInfo): Promise<BigNumber>;
45
46
  calculateAPY(denom: string, debtInfo?: DebtInfo, assetParams?: AssetParams, rateStrategyParams?: RateStrategyParams): Promise<BigNumber>;
47
+ calculateLendAPY(denom: string, borrowInterest?: BigNumber, debtInfo?: DebtInfo, params?: Params): Promise<BigNumber>;
46
48
  calculateInterestForTimePeriod(apy: BigNumber, start: Date, end: Date): BigNumber;
47
49
  recalculateCIM(denom: string, debtInfo?: DebtInfo): Promise<BigNumber>;
48
50
  recalculateStablecoinCIM(debtInfo?: StablecoinDebtInfo): Promise<BigNumber>;
@@ -610,6 +610,34 @@ class CDPModule extends base_1.default {
610
610
  }
611
611
  });
612
612
  }
613
+ calculateLendAPY(denom, borrowInterest, debtInfo, params) {
614
+ return __awaiter(this, void 0, void 0, function* () {
615
+ const sdk = this.sdkProvider;
616
+ if (!debtInfo) {
617
+ const debtInfoResponse = yield sdk.query.cdp.TokenDebt(query_1.QueryTokenDebtRequest.fromPartial({ denom }));
618
+ debtInfo = debtInfoResponse.debtInfo;
619
+ if (!debtInfo) {
620
+ throw new Error("unable to retrieve debt info for " + denom);
621
+ }
622
+ }
623
+ if (!borrowInterest) {
624
+ borrowInterest = yield this.calculateAPY(denom, debtInfo);
625
+ if (!borrowInterest) {
626
+ throw new Error("unable to retrieve borrow interest for " + denom);
627
+ }
628
+ }
629
+ if (!params) {
630
+ const paramsResponse = yield sdk.query.cdp.Params(codec_1.QueryCdpParamsRequest.fromPartial({}));
631
+ params = paramsResponse.params;
632
+ if (!params) {
633
+ throw new Error("unable to retrieve cdp params for " + denom);
634
+ }
635
+ }
636
+ const interestFeeRate = (0, number_1.bnOrZero)(params.interestFee).div(number_1.BN_10000);
637
+ const utilizationRate = (0, number_1.bnOrZero)(debtInfo.utilizationRate).shiftedBy(-18);
638
+ return borrowInterest.times(utilizationRate).times(number_1.BN_ONE.minus(interestFeeRate));
639
+ });
640
+ }
613
641
  calculateInterestForTimePeriod(apy, start, end) {
614
642
  if (end <= start) {
615
643
  return number_1.BN_ZERO;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.2.14-dev.6+f36a11ef9975",
3
+ "version": "0.2.14-dev.7+addbbc50fa65",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",