@scallop-io/sui-scallop-sdk 0.37.4 → 0.37.5
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 +139 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -4
- package/dist/index.mjs.map +1 -1
- package/dist/queries/market.d.ts +2 -2
- package/dist/types/data.d.ts +80 -8
- package/package.json +17 -16
- package/src/models/scallopClient.ts +1 -1
- package/src/models/scallopUtils.ts +1 -1
- package/src/queries/market.ts +199 -4
- package/src/txBuilders/quickMethods.ts +1 -1
- package/src/types/data.ts +112 -8
package/dist/index.js
CHANGED
|
@@ -519,7 +519,7 @@ var ScallopUtils = class {
|
|
|
519
519
|
* @return The selected transaction coin arguments.
|
|
520
520
|
*/
|
|
521
521
|
async selectCoins(owner, amount, coinType = import_sui.SUI_TYPE_ARG) {
|
|
522
|
-
const coins = await this._suiKit.
|
|
522
|
+
const coins = await this._suiKit.suiInteractor.selectCoins(
|
|
523
523
|
owner,
|
|
524
524
|
amount,
|
|
525
525
|
coinType
|
|
@@ -605,14 +605,149 @@ var ScallopUtils = class {
|
|
|
605
605
|
|
|
606
606
|
// src/queries/market.ts
|
|
607
607
|
var import_sui_kit2 = require("@scallop-io/sui-kit");
|
|
608
|
-
var
|
|
608
|
+
var import_bignumber = __toESM(require("bignumber.js"));
|
|
609
|
+
var queryMarket = async (scallopAddress, suiKit, scallopUtils) => {
|
|
609
610
|
const packageId = scallopAddress.get("core.packages.query.id");
|
|
610
611
|
const marketId = scallopAddress.get("core.market");
|
|
611
612
|
const txBlock = new import_sui_kit2.SuiTxBlock();
|
|
612
613
|
const queryTarget = `${packageId}::market_query::market_data`;
|
|
613
614
|
txBlock.moveCall(queryTarget, [marketId]);
|
|
614
615
|
const queryResult = await suiKit.inspectTxn(txBlock);
|
|
615
|
-
|
|
616
|
+
const marketData = queryResult.events[0].parsedJson;
|
|
617
|
+
const assets = [];
|
|
618
|
+
const collaterals = [];
|
|
619
|
+
for (const asset of marketData.pools) {
|
|
620
|
+
const coinType = "0x" + asset.type.name;
|
|
621
|
+
const borrowAPYFactor = 24 * 365 * 3600;
|
|
622
|
+
const baseBorrowRate = Number(asset.baseBorrowRatePerSec.value) / 2 ** 32;
|
|
623
|
+
const borrowRateOnHighKink = Number(asset.borrowRateOnHighKink.value) / 2 ** 32;
|
|
624
|
+
const borrowRateOnMidKink = Number(asset.borrowRateOnMidKink.value) / 2 ** 32;
|
|
625
|
+
const maxBorrowRate = Number(asset.maxBorrowRate.value) / 2 ** 32;
|
|
626
|
+
const highKink = Number(asset.highKink.value) / 2 ** 32;
|
|
627
|
+
const midKink = Number(asset.midKink.value) / 2 ** 32;
|
|
628
|
+
const borrowRate = Number(asset.interestRate.value) / 2 ** 32;
|
|
629
|
+
const borrowRateScale = Number(asset.interestRateScale);
|
|
630
|
+
const borrowIndex = Number(asset.borrowIndex);
|
|
631
|
+
const lastUpdated = Number(asset.lastUpdated);
|
|
632
|
+
const cash = Number(asset.cash);
|
|
633
|
+
const debt = Number(asset.debt);
|
|
634
|
+
const marketCoinSupply = Number(asset.marketCoinSupply);
|
|
635
|
+
const minBorrowAmount = Number(asset.minBorrowAmount);
|
|
636
|
+
const reserve = Number(asset.reserve);
|
|
637
|
+
const reserveFactor = Number(asset.reserveFactor.value) / 2 ** 32;
|
|
638
|
+
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();
|
|
644
|
+
const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - lastUpdated;
|
|
645
|
+
const borrowIndexDelta = (0, import_bignumber.default)(borrowIndex).multipliedBy((0, import_bignumber.default)(timeDelta).multipliedBy(borrowRate)).dividedBy(borrowRateScale);
|
|
646
|
+
const currentBorrowIndex = (0, import_bignumber.default)(borrowIndex).plus(borrowIndexDelta);
|
|
647
|
+
const growthInterest = (0, import_bignumber.default)(currentBorrowIndex).dividedBy(borrowIndex).minus(1);
|
|
648
|
+
const increasedDebt = (0, import_bignumber.default)(debt).multipliedBy(growthInterest);
|
|
649
|
+
const currentTotalDebt = increasedDebt.plus(debt);
|
|
650
|
+
const currentTotalReserve = (0, import_bignumber.default)(reserve).plus(
|
|
651
|
+
increasedDebt.multipliedBy(reserveFactor)
|
|
652
|
+
);
|
|
653
|
+
const currentTotalSupply = (0, import_bignumber.default)(currentTotalDebt).plus(
|
|
654
|
+
Math.max(cash - currentTotalReserve.toNumber(), 0)
|
|
655
|
+
);
|
|
656
|
+
let utilizationRate = (0, import_bignumber.default)(currentTotalDebt).dividedBy(currentTotalSupply);
|
|
657
|
+
utilizationRate = utilizationRate.isFinite() ? utilizationRate : (0, import_bignumber.default)(0);
|
|
658
|
+
let supplyRate = (0, import_bignumber.default)(caculatedBorrowRate).multipliedBy(utilizationRate).multipliedBy(1 - reserveFactor);
|
|
659
|
+
supplyRate = supplyRate.isFinite() ? supplyRate : (0, import_bignumber.default)(0);
|
|
660
|
+
const coin = scallopUtils.getCoinNameFromCoinType(
|
|
661
|
+
coinType
|
|
662
|
+
);
|
|
663
|
+
const symbol = coin.toUpperCase();
|
|
664
|
+
const marketCoinType = scallopUtils.parseMarketCoinType(
|
|
665
|
+
scallopAddress.get(`core.coins.${coin}.id`),
|
|
666
|
+
scallopAddress.get("core.packages.protocol.id"),
|
|
667
|
+
coin
|
|
668
|
+
);
|
|
669
|
+
const wrappedType = coin === "usdc" ? {
|
|
670
|
+
from: "Wormhole",
|
|
671
|
+
type: "Portal from Ethereum"
|
|
672
|
+
} : void 0;
|
|
673
|
+
assets.push({
|
|
674
|
+
coin,
|
|
675
|
+
symbol,
|
|
676
|
+
coinType,
|
|
677
|
+
wrappedType,
|
|
678
|
+
marketCoinType,
|
|
679
|
+
calculated: {
|
|
680
|
+
utilizationRate: utilizationRate.toNumber(),
|
|
681
|
+
baseBorrowRate: caculatedBaseBorrowRate,
|
|
682
|
+
borrowInterestRate: Math.min(
|
|
683
|
+
caculatedBorrowRate,
|
|
684
|
+
caculatedMaxBorrowRate
|
|
685
|
+
),
|
|
686
|
+
supplyInterestRate: supplyRate.toNumber(),
|
|
687
|
+
currentGrowthInterest: growthInterest.toNumber(),
|
|
688
|
+
currentBorrowIndex: currentBorrowIndex.toNumber(),
|
|
689
|
+
currentTotalSupply: currentTotalSupply.toNumber(),
|
|
690
|
+
currentTotalDebt: currentTotalDebt.toNumber(),
|
|
691
|
+
currentTotalReserve: currentTotalReserve.toNumber()
|
|
692
|
+
},
|
|
693
|
+
origin: {
|
|
694
|
+
highKink,
|
|
695
|
+
midKink,
|
|
696
|
+
baseBorrowRate: caculatedBaseBorrowRate,
|
|
697
|
+
borrowRateOnHighKink: caculatedBorrowRateOnHighKink,
|
|
698
|
+
borrowRateOnMidKink: caculatedBorrowRateOnMidKink,
|
|
699
|
+
borrowRate: caculatedBorrowRate,
|
|
700
|
+
maxBorrowRate: caculatedMaxBorrowRate,
|
|
701
|
+
reserveFactor,
|
|
702
|
+
borrowWeight,
|
|
703
|
+
borrowIndex,
|
|
704
|
+
lastUpdated,
|
|
705
|
+
debt,
|
|
706
|
+
cash,
|
|
707
|
+
marketCoinSupply,
|
|
708
|
+
minBorrowAmount,
|
|
709
|
+
reserve
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
for (const collateral of marketData.collaterals) {
|
|
714
|
+
const coinType = "0x" + collateral.type.name;
|
|
715
|
+
const collateralFactor = Number(collateral.collateralFactor.value) / 2 ** 32;
|
|
716
|
+
const liquidationFactor = Number(collateral.liquidationFactor.value) / 2 ** 32;
|
|
717
|
+
const liquidationDiscount = Number(collateral.liquidationDiscount.value) / 2 ** 32;
|
|
718
|
+
const liquidationPanelty = Number(collateral.liquidationPanelty.value) / 2 ** 32;
|
|
719
|
+
const liquidationReserveFactor = Number(collateral.liquidationReserveFactor.value) / 2 ** 32;
|
|
720
|
+
const maxCollateralAmount = Number(collateral.maxCollateralAmount);
|
|
721
|
+
const totalCollateralAmount = Number(collateral.totalCollateralAmount);
|
|
722
|
+
const coin = scallopUtils.getCoinNameFromCoinType(
|
|
723
|
+
coinType
|
|
724
|
+
);
|
|
725
|
+
const symbol = coin.toUpperCase();
|
|
726
|
+
const wrappedType = coin === "usdc" ? {
|
|
727
|
+
from: "Wormhole",
|
|
728
|
+
type: "Portal from Ethereum"
|
|
729
|
+
} : void 0;
|
|
730
|
+
collaterals.push({
|
|
731
|
+
coin,
|
|
732
|
+
symbol,
|
|
733
|
+
coinType,
|
|
734
|
+
wrappedType,
|
|
735
|
+
origin: {
|
|
736
|
+
collateralFactor,
|
|
737
|
+
liquidationFactor,
|
|
738
|
+
liquidationDiscount,
|
|
739
|
+
liquidationPanelty,
|
|
740
|
+
liquidationReserveFactor,
|
|
741
|
+
maxCollateralAmount,
|
|
742
|
+
totalCollateralAmount
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
return {
|
|
747
|
+
assets,
|
|
748
|
+
collaterals,
|
|
749
|
+
data: marketData
|
|
750
|
+
};
|
|
616
751
|
};
|
|
617
752
|
|
|
618
753
|
// src/queries/obligation.ts
|
|
@@ -1224,7 +1359,7 @@ var ScallopClient = class {
|
|
|
1224
1359
|
* @return Market data
|
|
1225
1360
|
*/
|
|
1226
1361
|
async queryMarket() {
|
|
1227
|
-
return queryMarket(this.address, this.suiKit);
|
|
1362
|
+
return queryMarket(this.address, this.suiKit, this._utils);
|
|
1228
1363
|
}
|
|
1229
1364
|
/**
|
|
1230
1365
|
* Query obligations data.
|