@scallop-io/sui-scallop-sdk 0.37.7 → 0.37.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/dist/constants/common.d.ts +2 -2
- package/dist/index.js +49 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -24
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +2 -1
- package/dist/queries/market.d.ts +1 -1
- package/package.json +1 -1
- package/src/constants/common.ts +6 -0
- package/src/models/scallopClient.ts +3 -2
- package/src/models/scallopUtils.ts +18 -0
- package/src/queries/market.ts +46 -34
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const API_BASE_URL = "https://sui.api.scallop.io";
|
|
2
2
|
export declare const ADDRESSES_ID = "6462a088a7ace142bb6d7e9b";
|
|
3
|
-
export declare const SUPPORT_ASSET_COINS: readonly ["eth", "btc", "usdc", "usdt", "sui"];
|
|
4
|
-
export declare const SUPPORT_COLLATERAL_COINS: readonly ["eth", "btc", "usdc", "usdt", "sui"];
|
|
3
|
+
export declare const SUPPORT_ASSET_COINS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus"];
|
|
4
|
+
export declare const SUPPORT_COLLATERAL_COINS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus"];
|
|
5
5
|
export declare const SUPPORT_ORACLES: readonly ["supra", "switchboard", "pyth"];
|
|
6
6
|
export declare const SUPPORT_PACKAGES: readonly ["coinDecimalsRegistry", "math", "whitelist", "x", "protocol", "query", "supra", "pyth", "switchboard", "xOracle", "testCoin"];
|
|
7
7
|
export declare const SUI_COIN_TYPE_ARG_REGEX: RegExp;
|
package/dist/index.js
CHANGED
|
@@ -52,14 +52,20 @@ var SUPPORT_ASSET_COINS = [
|
|
|
52
52
|
"btc",
|
|
53
53
|
"usdc",
|
|
54
54
|
"usdt",
|
|
55
|
-
"sui"
|
|
55
|
+
"sui",
|
|
56
|
+
"apt",
|
|
57
|
+
"sol",
|
|
58
|
+
"cetus"
|
|
56
59
|
];
|
|
57
60
|
var SUPPORT_COLLATERAL_COINS = [
|
|
58
61
|
"eth",
|
|
59
62
|
"btc",
|
|
60
63
|
"usdc",
|
|
61
64
|
"usdt",
|
|
62
|
-
"sui"
|
|
65
|
+
"sui",
|
|
66
|
+
"apt",
|
|
67
|
+
"sol",
|
|
68
|
+
"cetus"
|
|
63
69
|
];
|
|
64
70
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
65
71
|
var SUPPORT_PACKAGES = [
|
|
@@ -558,7 +564,13 @@ var ScallopUtils = class {
|
|
|
558
564
|
// USDT
|
|
559
565
|
"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
|
|
560
566
|
// ETH
|
|
561
|
-
"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5"
|
|
567
|
+
"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
568
|
+
// BTC
|
|
569
|
+
"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
|
|
570
|
+
// SOL
|
|
571
|
+
"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
|
|
572
|
+
// APT
|
|
573
|
+
"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37"
|
|
562
574
|
];
|
|
563
575
|
if (wormHoleCoins.includes(coinPackageId)) {
|
|
564
576
|
return `${coinPackageId}::coin::COIN`;
|
|
@@ -579,7 +591,13 @@ var ScallopUtils = class {
|
|
|
579
591
|
// USDT
|
|
580
592
|
"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",
|
|
581
593
|
// ETH
|
|
582
|
-
"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
|
|
594
|
+
"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN",
|
|
595
|
+
// BTC
|
|
596
|
+
"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN",
|
|
597
|
+
// SOL
|
|
598
|
+
"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8::coin::COIN",
|
|
599
|
+
// APT
|
|
600
|
+
"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37::coin::COIN"
|
|
583
601
|
];
|
|
584
602
|
if (coinType === wormHoleCoinTypes[0]) {
|
|
585
603
|
return "usdc";
|
|
@@ -587,6 +605,12 @@ var ScallopUtils = class {
|
|
|
587
605
|
return "usdt";
|
|
588
606
|
} else if (coinType === wormHoleCoinTypes[2]) {
|
|
589
607
|
return "eth";
|
|
608
|
+
} else if (coinType === wormHoleCoinTypes[3]) {
|
|
609
|
+
return "btc";
|
|
610
|
+
} else if (coinType === wormHoleCoinTypes[4]) {
|
|
611
|
+
return "sol";
|
|
612
|
+
} else if (coinType === wormHoleCoinTypes[5]) {
|
|
613
|
+
return "apt";
|
|
590
614
|
} else {
|
|
591
615
|
return coinType.split("::")[2].toLowerCase();
|
|
592
616
|
}
|
|
@@ -612,7 +636,7 @@ var ScallopUtils = class {
|
|
|
612
636
|
// src/queries/market.ts
|
|
613
637
|
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
614
638
|
var import_bignumber = __toESM(require("bignumber.js"));
|
|
615
|
-
var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
|
|
639
|
+
var queryMarket = async (scallopAddress, suiKit, scallopUtils, rateType) => {
|
|
616
640
|
const packageId = scallopAddress.get("core.packages.query.id");
|
|
617
641
|
const marketId = scallopAddress.get("core.market");
|
|
618
642
|
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
@@ -624,7 +648,7 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
|
|
|
624
648
|
const collaterals = [];
|
|
625
649
|
for (const asset of marketData.pools) {
|
|
626
650
|
const coinType = "0x" + asset.type.name;
|
|
627
|
-
const
|
|
651
|
+
const borrowYearFactor = 24 * 365 * 3600;
|
|
628
652
|
const baseBorrowRate = Number(asset.baseBorrowRatePerSec.value) / 2 ** 32;
|
|
629
653
|
const borrowRateOnHighKink = Number(asset.borrowRateOnHighKink.value) / 2 ** 32;
|
|
630
654
|
const borrowRateOnMidKink = Number(asset.borrowRateOnMidKink.value) / 2 ** 32;
|
|
@@ -642,11 +666,11 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
|
|
|
642
666
|
const reserve = Number(asset.reserve);
|
|
643
667
|
const reserveFactor = Number(asset.reserveFactor.value) / 2 ** 32;
|
|
644
668
|
const borrowWeight = Number(asset.borrowWeight.value) / 2 ** 32;
|
|
645
|
-
const
|
|
646
|
-
const
|
|
647
|
-
const
|
|
648
|
-
const
|
|
649
|
-
const
|
|
669
|
+
const calculatedBaseBorrowRate = rateType === "apr" ? baseBorrowRate * borrowYearFactor / borrowRateScale : (1 + baseBorrowRate / borrowRateScale) ** borrowYearFactor - 1;
|
|
670
|
+
const calculatedBorrowRateOnHighKink = rateType === "apr" ? borrowRateOnHighKink * borrowYearFactor / borrowRateScale : (1 + borrowRateOnHighKink / borrowRateScale) ** borrowYearFactor - 1;
|
|
671
|
+
const calculatedBorrowRateOnMidKink = rateType === "apr" ? borrowRateOnMidKink * borrowYearFactor / borrowRateScale : (1 + borrowRateOnMidKink / borrowRateScale) ** borrowYearFactor - 1;
|
|
672
|
+
const calculatedMaxBorrowRate = rateType === "apr" ? maxBorrowRate * borrowYearFactor / borrowRateScale : (1 + maxBorrowRate / borrowRateScale) ** borrowYearFactor - 1;
|
|
673
|
+
const calculatedBorrowRate = rateType === "apr" ? borrowRate * borrowYearFactor / borrowRateScale : (1 + borrowRate / borrowRateScale) ** borrowYearFactor - 1;
|
|
650
674
|
const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - lastUpdated;
|
|
651
675
|
const borrowIndexDelta = (0, import_bignumber.default)(borrowIndex).multipliedBy((0, import_bignumber.default)(timeDelta).multipliedBy(borrowRate)).dividedBy(borrowRateScale);
|
|
652
676
|
const currentBorrowIndex = (0, import_bignumber.default)(borrowIndex).plus(borrowIndexDelta);
|
|
@@ -661,7 +685,7 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
|
|
|
661
685
|
);
|
|
662
686
|
let utilizationRate = (0, import_bignumber.default)(currentTotalDebt).dividedBy(currentTotalSupply);
|
|
663
687
|
utilizationRate = utilizationRate.isFinite() ? utilizationRate : (0, import_bignumber.default)(0);
|
|
664
|
-
let supplyRate = (0, import_bignumber.default)(
|
|
688
|
+
let supplyRate = (0, import_bignumber.default)(calculatedBorrowRate).multipliedBy(utilizationRate).multipliedBy(1 - reserveFactor);
|
|
665
689
|
supplyRate = supplyRate.isFinite() ? supplyRate : (0, import_bignumber.default)(0);
|
|
666
690
|
const coin = scallopUtils.getCoinNameFromCoinType(
|
|
667
691
|
coinType
|
|
@@ -672,7 +696,7 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
|
|
|
672
696
|
scallopAddress.get("core.packages.protocol.id"),
|
|
673
697
|
coin
|
|
674
698
|
);
|
|
675
|
-
const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" ? {
|
|
699
|
+
const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" || coin === "btc" || coin === "apt" || coin === "sol" ? {
|
|
676
700
|
from: "Wormhole",
|
|
677
701
|
type: "Portal from Ethereum"
|
|
678
702
|
} : void 0;
|
|
@@ -684,10 +708,10 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
|
|
|
684
708
|
marketCoinType,
|
|
685
709
|
calculated: {
|
|
686
710
|
utilizationRate: utilizationRate.toNumber(),
|
|
687
|
-
baseBorrowRate:
|
|
711
|
+
baseBorrowRate: calculatedBaseBorrowRate,
|
|
688
712
|
borrowInterestRate: Math.min(
|
|
689
|
-
|
|
690
|
-
|
|
713
|
+
calculatedBorrowRate,
|
|
714
|
+
calculatedMaxBorrowRate
|
|
691
715
|
),
|
|
692
716
|
supplyInterestRate: supplyRate.toNumber(),
|
|
693
717
|
currentGrowthInterest: growthInterest.toNumber(),
|
|
@@ -699,11 +723,11 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
|
|
|
699
723
|
origin: {
|
|
700
724
|
highKink,
|
|
701
725
|
midKink,
|
|
702
|
-
baseBorrowRate:
|
|
703
|
-
borrowRateOnHighKink:
|
|
704
|
-
borrowRateOnMidKink:
|
|
705
|
-
borrowRate:
|
|
706
|
-
maxBorrowRate:
|
|
726
|
+
baseBorrowRate: calculatedBaseBorrowRate,
|
|
727
|
+
borrowRateOnHighKink: calculatedBorrowRateOnHighKink,
|
|
728
|
+
borrowRateOnMidKink: calculatedBorrowRateOnMidKink,
|
|
729
|
+
borrowRate: calculatedBorrowRate,
|
|
730
|
+
maxBorrowRate: calculatedMaxBorrowRate,
|
|
707
731
|
reserveFactor,
|
|
708
732
|
borrowWeight,
|
|
709
733
|
borrowIndex,
|
|
@@ -729,7 +753,7 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
|
|
|
729
753
|
coinType
|
|
730
754
|
);
|
|
731
755
|
const symbol = coin.toUpperCase();
|
|
732
|
-
const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" ? {
|
|
756
|
+
const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" || coin === "btc" || coin === "apt" || coin === "sol" ? {
|
|
733
757
|
from: "Wormhole",
|
|
734
758
|
type: "Portal from Ethereum"
|
|
735
759
|
} : void 0;
|
|
@@ -1362,10 +1386,11 @@ var ScallopClient = class {
|
|
|
1362
1386
|
/**
|
|
1363
1387
|
* Query market data.
|
|
1364
1388
|
*
|
|
1389
|
+
* @param rateType - How interest rates are calculated.
|
|
1365
1390
|
* @return Market data
|
|
1366
1391
|
*/
|
|
1367
|
-
async queryMarket() {
|
|
1368
|
-
return queryMarket(this.address, this.suiKit, this._utils);
|
|
1392
|
+
async queryMarket(rateType = "apr") {
|
|
1393
|
+
return queryMarket(this.address, this.suiKit, this._utils, rateType);
|
|
1369
1394
|
}
|
|
1370
1395
|
/**
|
|
1371
1396
|
* Query obligations data.
|