@scallop-io/sui-scallop-sdk 0.37.6 → 0.37.8

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
@@ -556,7 +556,9 @@ var ScallopUtils = class {
556
556
  // USDC
557
557
  "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
558
558
  // USDT
559
- "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c"
559
+ "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
560
+ // ETH
561
+ "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5"
560
562
  ];
561
563
  if (wormHoleCoins.includes(coinPackageId)) {
562
564
  return `${coinPackageId}::coin::COIN`;
@@ -575,12 +577,16 @@ var ScallopUtils = class {
575
577
  // USDC
576
578
  "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
577
579
  // USDT
578
- "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN"
580
+ "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",
581
+ // ETH
582
+ "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
579
583
  ];
580
584
  if (coinType === wormHoleCoinTypes[0]) {
581
585
  return "usdc";
582
586
  } else if (coinType === wormHoleCoinTypes[1]) {
583
587
  return "usdt";
588
+ } else if (coinType === wormHoleCoinTypes[2]) {
589
+ return "eth";
584
590
  } else {
585
591
  return coinType.split("::")[2].toLowerCase();
586
592
  }
@@ -606,7 +612,7 @@ var ScallopUtils = class {
606
612
  // src/queries/market.ts
607
613
  var import_sui_kit2 = require("@scallop-io/sui-kit");
608
614
  var import_bignumber = __toESM(require("bignumber.js"));
609
- var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
615
+ var queryMarket = async (scallopAddress, suiKit, scallopUtils, rateType) => {
610
616
  const packageId = scallopAddress.get("core.packages.query.id");
611
617
  const marketId = scallopAddress.get("core.market");
612
618
  const txBlock = new import_sui_kit2.SuiTxBlock();
@@ -618,7 +624,7 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
618
624
  const collaterals = [];
619
625
  for (const asset of marketData.pools) {
620
626
  const coinType = "0x" + asset.type.name;
621
- const borrowAPYFactor = 24 * 365 * 3600;
627
+ const borrowYearFactor = 24 * 365 * 3600;
622
628
  const baseBorrowRate = Number(asset.baseBorrowRatePerSec.value) / 2 ** 32;
623
629
  const borrowRateOnHighKink = Number(asset.borrowRateOnHighKink.value) / 2 ** 32;
624
630
  const borrowRateOnMidKink = Number(asset.borrowRateOnMidKink.value) / 2 ** 32;
@@ -636,11 +642,11 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
636
642
  const reserve = Number(asset.reserve);
637
643
  const reserveFactor = Number(asset.reserveFactor.value) / 2 ** 32;
638
644
  const borrowWeight = Number(asset.borrowWeight.value) / 2 ** 32;
639
- const caculatedBaseBorrowRate = (0, import_bignumber.default)(baseBorrowRate).multipliedBy(borrowAPYFactor).dividedBy(borrowRateScale).toNumber();
640
- const caculatedBorrowRateOnHighKink = (0, import_bignumber.default)(borrowRateOnHighKink).multipliedBy(borrowAPYFactor).dividedBy(borrowRateScale).toNumber();
641
- const caculatedBorrowRateOnMidKink = (0, import_bignumber.default)(borrowRateOnMidKink).multipliedBy(borrowAPYFactor).dividedBy(borrowRateScale).toNumber();
642
- const caculatedMaxBorrowRate = (0, import_bignumber.default)(maxBorrowRate).multipliedBy(borrowAPYFactor).dividedBy(borrowRateScale).toNumber();
643
- const caculatedBorrowRate = (0, import_bignumber.default)(borrowRate).multipliedBy(borrowAPYFactor).dividedBy(borrowRateScale).toNumber();
645
+ const calculatedBaseBorrowRate = rateType === "apr" ? baseBorrowRate * borrowYearFactor / borrowRateScale : (1 + baseBorrowRate / borrowRateScale) ** borrowYearFactor - 1;
646
+ const calculatedBorrowRateOnHighKink = rateType === "apr" ? borrowRateOnHighKink * borrowYearFactor / borrowRateScale : (1 + borrowRateOnHighKink / borrowRateScale) ** borrowYearFactor - 1;
647
+ const calculatedBorrowRateOnMidKink = rateType === "apr" ? borrowRateOnMidKink * borrowYearFactor / borrowRateScale : (1 + borrowRateOnMidKink / borrowRateScale) ** borrowYearFactor - 1;
648
+ const calculatedMaxBorrowRate = rateType === "apr" ? maxBorrowRate * borrowYearFactor / borrowRateScale : (1 + maxBorrowRate / borrowRateScale) ** borrowYearFactor - 1;
649
+ const calculatedBorrowRate = rateType === "apr" ? borrowRate * borrowYearFactor / borrowRateScale : (1 + borrowRate / borrowRateScale) ** borrowYearFactor - 1;
644
650
  const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - lastUpdated;
645
651
  const borrowIndexDelta = (0, import_bignumber.default)(borrowIndex).multipliedBy((0, import_bignumber.default)(timeDelta).multipliedBy(borrowRate)).dividedBy(borrowRateScale);
646
652
  const currentBorrowIndex = (0, import_bignumber.default)(borrowIndex).plus(borrowIndexDelta);
@@ -655,7 +661,7 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
655
661
  );
656
662
  let utilizationRate = (0, import_bignumber.default)(currentTotalDebt).dividedBy(currentTotalSupply);
657
663
  utilizationRate = utilizationRate.isFinite() ? utilizationRate : (0, import_bignumber.default)(0);
658
- let supplyRate = (0, import_bignumber.default)(caculatedBorrowRate).multipliedBy(utilizationRate).multipliedBy(1 - reserveFactor);
664
+ let supplyRate = (0, import_bignumber.default)(calculatedBorrowRate).multipliedBy(utilizationRate).multipliedBy(1 - reserveFactor);
659
665
  supplyRate = supplyRate.isFinite() ? supplyRate : (0, import_bignumber.default)(0);
660
666
  const coin = scallopUtils.getCoinNameFromCoinType(
661
667
  coinType
@@ -666,7 +672,7 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
666
672
  scallopAddress.get("core.packages.protocol.id"),
667
673
  coin
668
674
  );
669
- const wrappedType = coin === "usdc" ? {
675
+ const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" ? {
670
676
  from: "Wormhole",
671
677
  type: "Portal from Ethereum"
672
678
  } : void 0;
@@ -678,10 +684,10 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
678
684
  marketCoinType,
679
685
  calculated: {
680
686
  utilizationRate: utilizationRate.toNumber(),
681
- baseBorrowRate: caculatedBaseBorrowRate,
687
+ baseBorrowRate: calculatedBaseBorrowRate,
682
688
  borrowInterestRate: Math.min(
683
- caculatedBorrowRate,
684
- caculatedMaxBorrowRate
689
+ calculatedBorrowRate,
690
+ calculatedMaxBorrowRate
685
691
  ),
686
692
  supplyInterestRate: supplyRate.toNumber(),
687
693
  currentGrowthInterest: growthInterest.toNumber(),
@@ -693,11 +699,11 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
693
699
  origin: {
694
700
  highKink,
695
701
  midKink,
696
- baseBorrowRate: caculatedBaseBorrowRate,
697
- borrowRateOnHighKink: caculatedBorrowRateOnHighKink,
698
- borrowRateOnMidKink: caculatedBorrowRateOnMidKink,
699
- borrowRate: caculatedBorrowRate,
700
- maxBorrowRate: caculatedMaxBorrowRate,
702
+ baseBorrowRate: calculatedBaseBorrowRate,
703
+ borrowRateOnHighKink: calculatedBorrowRateOnHighKink,
704
+ borrowRateOnMidKink: calculatedBorrowRateOnMidKink,
705
+ borrowRate: calculatedBorrowRate,
706
+ maxBorrowRate: calculatedMaxBorrowRate,
701
707
  reserveFactor,
702
708
  borrowWeight,
703
709
  borrowIndex,
@@ -723,7 +729,7 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
723
729
  coinType
724
730
  );
725
731
  const symbol = coin.toUpperCase();
726
- const wrappedType = coin === "usdc" ? {
732
+ const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" ? {
727
733
  from: "Wormhole",
728
734
  type: "Portal from Ethereum"
729
735
  } : void 0;
@@ -1356,10 +1362,11 @@ var ScallopClient = class {
1356
1362
  /**
1357
1363
  * Query market data.
1358
1364
  *
1365
+ * @param rateType - How interest rates are calculated.
1359
1366
  * @return Market data
1360
1367
  */
1361
- async queryMarket() {
1362
- return queryMarket(this.address, this.suiKit, this._utils);
1368
+ async queryMarket(rateType = "apr") {
1369
+ return queryMarket(this.address, this.suiKit, this._utils, rateType);
1363
1370
  }
1364
1371
  /**
1365
1372
  * Query obligations data.