@suilend/sdk 1.0.7 → 1.0.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/core/api/events.d.ts +3 -0
- package/core/api/events.js +3 -0
- package/core/parsers/apiReserveAssetDataEvent.d.ts +10 -10
- package/core/parsers/apiReserveAssetDataEvent.js +23 -42
- package/core/parsers/deps.d.ts +3 -3
- package/core/parsers/rateLimiter.js +2 -1
- package/core/parsers/reserve.js +3 -5
- package/core/types.d.ts +164 -0
- package/core/utils/events.d.ts +176 -0
- package/core/utils/events.js +104 -0
- package/core/utils/simulate.d.ts +56 -0
- package/core/utils/simulate.js +317 -0
- package/core/utils/utils.d.ts +61 -0
- package/core/utils/utils.js +157 -0
- package/mainnet/utils/events.d.ts +1 -144
- package/mainnet/utils/events.js +14 -112
- package/mainnet/utils/obligation.d.ts +4 -4
- package/mainnet/utils/simulate.d.ts +30 -14
- package/mainnet/utils/simulate.js +53 -259
- package/mainnet/utils/utils.d.ts +1 -79
- package/mainnet/utils/utils.js +15 -155
- package/package.json +1 -1
package/core/api/events.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { DownsampledApiReserveAssetDataEvent } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Note: This SDK function is experimental and may change or require authentication in the future.
|
|
4
|
+
*/
|
|
2
5
|
export declare const fetchDownsampledApiReserveAssetDataEvents: (reserveId: string, days: number, sampleIntervalS: number) => Promise<DownsampledApiReserveAssetDataEvent[]>;
|
package/core/api/events.js
CHANGED
|
@@ -10,6 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.fetchDownsampledApiReserveAssetDataEvents = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Note: This SDK function is experimental and may change or require authentication in the future.
|
|
15
|
+
*/
|
|
13
16
|
const fetchDownsampledApiReserveAssetDataEvents = (reserveId, days, sampleIntervalS) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
17
|
const url = `https://api.suilend.fi/events/downsampled-reserve-asset-data?reserveId=${reserveId}&days=${days}&sampleIntervalS=${sampleIntervalS}`;
|
|
15
18
|
const res = yield fetch(url);
|
|
@@ -4,20 +4,19 @@ import { ParsedReserve } from "./reserve";
|
|
|
4
4
|
export type ParsedReserveAssetDataEvent = ReturnType<typeof parseReserveAssetDataEvent>;
|
|
5
5
|
export declare const parseReserveAssetDataEvent: (event: ApiReserveAssetDataEvent, reserve: ParsedReserve) => {
|
|
6
6
|
id: number;
|
|
7
|
-
|
|
7
|
+
lendingMarketId: string;
|
|
8
8
|
coinType: string;
|
|
9
9
|
reserveId: string;
|
|
10
|
+
availableAmount: BigNumber;
|
|
10
11
|
depositedAmount: BigNumber;
|
|
11
12
|
borrowedAmount: BigNumber;
|
|
12
|
-
|
|
13
|
+
availableAmountUsd: BigNumber;
|
|
13
14
|
depositedAmountUsd: BigNumber;
|
|
14
15
|
borrowedAmountUsd: BigNumber;
|
|
15
|
-
availableAmountUsd: BigNumber;
|
|
16
|
-
utilizationPercent: BigNumber;
|
|
17
16
|
borrowAprPercent: BigNumber;
|
|
18
17
|
depositAprPercent: BigNumber;
|
|
19
18
|
ctokenSupply: BigNumber;
|
|
20
|
-
cumulativeBorrowRate:
|
|
19
|
+
cumulativeBorrowRate: BigNumber;
|
|
21
20
|
price: BigNumber;
|
|
22
21
|
smoothedPrice: BigNumber;
|
|
23
22
|
minPrice: BigNumber;
|
|
@@ -27,25 +26,25 @@ export declare const parseReserveAssetDataEvent: (event: ApiReserveAssetDataEven
|
|
|
27
26
|
digest: string;
|
|
28
27
|
eventIndex: number;
|
|
29
28
|
sender: string;
|
|
29
|
+
utilizationPercent: BigNumber;
|
|
30
30
|
};
|
|
31
31
|
export type ParsedDownsampledApiReserveAssetDataEvent = ReturnType<typeof parseDownsampledApiReserveAssetDataEvent>;
|
|
32
32
|
export declare const parseDownsampledApiReserveAssetDataEvent: (event: DownsampledApiReserveAssetDataEvent, reserve: ParsedReserve) => {
|
|
33
33
|
sampleTimestampS: number;
|
|
34
34
|
id: number;
|
|
35
|
-
|
|
35
|
+
lendingMarketId: string;
|
|
36
36
|
coinType: string;
|
|
37
37
|
reserveId: string;
|
|
38
|
+
availableAmount: BigNumber;
|
|
38
39
|
depositedAmount: BigNumber;
|
|
39
40
|
borrowedAmount: BigNumber;
|
|
40
|
-
|
|
41
|
+
availableAmountUsd: BigNumber;
|
|
41
42
|
depositedAmountUsd: BigNumber;
|
|
42
43
|
borrowedAmountUsd: BigNumber;
|
|
43
|
-
availableAmountUsd: BigNumber;
|
|
44
|
-
utilizationPercent: BigNumber;
|
|
45
44
|
borrowAprPercent: BigNumber;
|
|
46
45
|
depositAprPercent: BigNumber;
|
|
47
46
|
ctokenSupply: BigNumber;
|
|
48
|
-
cumulativeBorrowRate:
|
|
47
|
+
cumulativeBorrowRate: BigNumber;
|
|
49
48
|
price: BigNumber;
|
|
50
49
|
smoothedPrice: BigNumber;
|
|
51
50
|
minPrice: BigNumber;
|
|
@@ -55,4 +54,5 @@ export declare const parseDownsampledApiReserveAssetDataEvent: (event: Downsampl
|
|
|
55
54
|
digest: string;
|
|
56
55
|
eventIndex: number;
|
|
57
56
|
sender: string;
|
|
57
|
+
utilizationPercent: BigNumber;
|
|
58
58
|
};
|
|
@@ -7,68 +7,48 @@ exports.parseDownsampledApiReserveAssetDataEvent = exports.parseReserveAssetData
|
|
|
7
7
|
const utils_1 = require("@mysten/sui.js/utils");
|
|
8
8
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
9
|
const constants_1 = require("../constants");
|
|
10
|
-
const calculateBorrowAprPercent = (utilizationPercent, reserve) => {
|
|
11
|
-
const config = reserve.config;
|
|
12
|
-
let i = 1;
|
|
13
|
-
while (i < config.interestRate.length) {
|
|
14
|
-
const leftUtilPercent = config.interestRate[i - 1].utilPercent;
|
|
15
|
-
const leftAprPercent = config.interestRate[i - 1].aprPercent;
|
|
16
|
-
const rightUtilPercent = config.interestRate[i].utilPercent;
|
|
17
|
-
const rightAprPercent = config.interestRate[i].aprPercent;
|
|
18
|
-
if (utilizationPercent.gte(leftUtilPercent) &&
|
|
19
|
-
utilizationPercent.lte(rightUtilPercent)) {
|
|
20
|
-
const weight = new bignumber_js_1.default(utilizationPercent.minus(leftUtilPercent)).div(rightUtilPercent.minus(leftUtilPercent));
|
|
21
|
-
return leftAprPercent.plus(weight.times(rightAprPercent.minus(leftAprPercent)));
|
|
22
|
-
}
|
|
23
|
-
i = i + 1;
|
|
24
|
-
}
|
|
25
|
-
// Should never reach here
|
|
26
|
-
return new bignumber_js_1.default(0);
|
|
27
|
-
};
|
|
28
10
|
const parseReserveAssetDataEvent = (event, reserve) => {
|
|
29
|
-
const
|
|
11
|
+
const availableAmount = new bignumber_js_1.default(event.availableAmount)
|
|
30
12
|
.div(constants_1.WAD)
|
|
31
13
|
.div(10 ** reserve.mintDecimals);
|
|
32
|
-
const
|
|
14
|
+
const depositedAmount = new bignumber_js_1.default(event.supplyAmount)
|
|
33
15
|
.div(constants_1.WAD)
|
|
34
16
|
.div(10 ** reserve.mintDecimals);
|
|
35
|
-
const
|
|
17
|
+
const borrowedAmount = new bignumber_js_1.default(event.borrowedAmount)
|
|
36
18
|
.div(constants_1.WAD)
|
|
37
19
|
.div(10 ** reserve.mintDecimals);
|
|
20
|
+
const availableAmountUsd = new bignumber_js_1.default(event.availableAmountUsdEstimate).div(constants_1.WAD);
|
|
21
|
+
const depositedAmountUsd = new bignumber_js_1.default(event.supplyAmountUsdEstimate).div(constants_1.WAD);
|
|
22
|
+
const borrowedAmountUsd = new bignumber_js_1.default(event.borrowedAmountUsdEstimate).div(constants_1.WAD);
|
|
23
|
+
const borrowAprPercent = new bignumber_js_1.default(event.borrowApr).div(constants_1.WAD).times(100);
|
|
24
|
+
const depositAprPercent = new bignumber_js_1.default(event.supplyApr).div(constants_1.WAD).times(100);
|
|
38
25
|
const ctokenSupply = new bignumber_js_1.default(event.ctokenSupply).div(10 ** reserve.mintDecimals);
|
|
39
|
-
const
|
|
40
|
-
? new bignumber_js_1.default(0)
|
|
41
|
-
: borrowedAmount.div(depositedAmount).times(100);
|
|
42
|
-
const borrowAprPercent = calculateBorrowAprPercent(utilizationPercent, reserve);
|
|
43
|
-
const depositAprPercent = utilizationPercent
|
|
44
|
-
.div(100)
|
|
45
|
-
.times(borrowAprPercent.div(100))
|
|
46
|
-
.times(new bignumber_js_1.default(100).minus(new bignumber_js_1.default(reserve.config.spreadFeeBps).div(100)));
|
|
26
|
+
const cumulativeBorrowRate = new bignumber_js_1.default(event.cumulativeBorrowRate).div(constants_1.WAD);
|
|
47
27
|
const price = new bignumber_js_1.default(event.price).div(constants_1.WAD);
|
|
48
28
|
const smoothedPrice = new bignumber_js_1.default(event.smoothedPrice).div(constants_1.WAD);
|
|
49
29
|
const minPrice = bignumber_js_1.default.min(price, smoothedPrice);
|
|
50
30
|
const maxPrice = bignumber_js_1.default.max(price, smoothedPrice);
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
31
|
+
// Custom
|
|
32
|
+
const utilizationPercent = depositedAmount.eq(0)
|
|
33
|
+
? new bignumber_js_1.default(0)
|
|
34
|
+
: borrowedAmount.div(depositedAmount).times(100);
|
|
54
35
|
return {
|
|
55
36
|
id: event.id,
|
|
56
|
-
|
|
37
|
+
lendingMarketId: event.lendingMarketId,
|
|
57
38
|
coinType: (0, utils_1.normalizeStructTag)(event.coinType),
|
|
58
39
|
reserveId: event.reserveId,
|
|
40
|
+
availableAmount,
|
|
59
41
|
depositedAmount,
|
|
60
42
|
borrowedAmount,
|
|
61
|
-
|
|
43
|
+
availableAmountUsd,
|
|
62
44
|
depositedAmountUsd,
|
|
63
45
|
borrowedAmountUsd,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
price: price,
|
|
71
|
-
smoothedPrice: smoothedPrice,
|
|
46
|
+
borrowAprPercent,
|
|
47
|
+
depositAprPercent,
|
|
48
|
+
ctokenSupply,
|
|
49
|
+
cumulativeBorrowRate,
|
|
50
|
+
price,
|
|
51
|
+
smoothedPrice,
|
|
72
52
|
minPrice,
|
|
73
53
|
maxPrice,
|
|
74
54
|
priceLastUpdateTimestampS: event.priceLastUpdateTimestampS,
|
|
@@ -76,6 +56,7 @@ const parseReserveAssetDataEvent = (event, reserve) => {
|
|
|
76
56
|
digest: event.digest,
|
|
77
57
|
eventIndex: event.eventIndex,
|
|
78
58
|
sender: event.sender,
|
|
59
|
+
utilizationPercent,
|
|
79
60
|
};
|
|
80
61
|
};
|
|
81
62
|
exports.parseReserveAssetDataEvent = parseReserveAssetDataEvent;
|
package/core/parsers/deps.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ export interface Deps {
|
|
|
6
6
|
PoolRewardManager: any;
|
|
7
7
|
PoolReward: any;
|
|
8
8
|
simulate: {
|
|
9
|
+
calculateUtilizationPercent: (reserve: Deps["Reserve"]) => BigNumber;
|
|
10
|
+
calculateBorrowAprPercent: (reserve: Deps["Reserve"]) => BigNumber;
|
|
11
|
+
calculateDepositAprPercent: (reserve: Deps["Reserve"]) => BigNumber;
|
|
9
12
|
cTokenRatio: (reserve: Deps["Reserve"]) => BigNumber;
|
|
10
|
-
calculateBorrowApr: (reserve: Deps["Reserve"]) => BigNumber;
|
|
11
|
-
calculateSupplyApr: (reserve: Deps["Reserve"]) => BigNumber;
|
|
12
|
-
calculateUtilizationRate: (reserve: Deps["Reserve"]) => BigNumber;
|
|
13
13
|
};
|
|
14
14
|
RateLimiter: any;
|
|
15
15
|
}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseRateLimiterConfig = exports.parseRateLimiter = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
const constants_1 = require("../constants");
|
|
8
9
|
const parseRateLimiter = ({ RateLimiter }, rateLimiter, currentTime) => {
|
|
9
10
|
const config = (0, exports.parseRateLimiterConfig)({ RateLimiter }, rateLimiter);
|
|
10
11
|
const $typeName = rateLimiter.$typeName;
|
|
@@ -18,7 +19,7 @@ const parseRateLimiter = ({ RateLimiter }, rateLimiter, currentTime) => {
|
|
|
18
19
|
const currentOutflow = prevWeight
|
|
19
20
|
.times(new bignumber_js_1.default(prevQty.toString()))
|
|
20
21
|
.plus(new bignumber_js_1.default(curQty.toString()))
|
|
21
|
-
.div(
|
|
22
|
+
.div(constants_1.WAD);
|
|
22
23
|
const remainingOutflow = currentOutflow.gt(config.maxOutflow.toString())
|
|
23
24
|
? new bignumber_js_1.default(0)
|
|
24
25
|
: new bignumber_js_1.default(config.maxOutflow.toString()).minus(currentOutflow);
|
package/core/parsers/reserve.js
CHANGED
|
@@ -44,11 +44,9 @@ const parseReserve = ({ Reserve, PoolRewardManager, PoolReward, simulate, }, res
|
|
|
44
44
|
.minus(unclaimedSpreadFees);
|
|
45
45
|
const depositedAmountUsd = depositedAmount.times(price);
|
|
46
46
|
const cTokenExchangeRate = simulate.cTokenRatio(reserve);
|
|
47
|
-
const borrowAprPercent = simulate.
|
|
48
|
-
const depositAprPercent = simulate.
|
|
49
|
-
const utilizationPercent = simulate
|
|
50
|
-
.calculateUtilizationRate(reserve)
|
|
51
|
-
.times(100);
|
|
47
|
+
const borrowAprPercent = simulate.calculateBorrowAprPercent(reserve);
|
|
48
|
+
const depositAprPercent = simulate.calculateDepositAprPercent(reserve);
|
|
49
|
+
const utilizationPercent = simulate.calculateUtilizationPercent(reserve);
|
|
52
50
|
const symbol = coinMetadata.symbol;
|
|
53
51
|
const name = coinMetadata.name;
|
|
54
52
|
const iconUrl = coinMetadata.iconUrl;
|
package/core/types.d.ts
CHANGED
|
@@ -672,6 +672,27 @@ export interface MigrateArgs {
|
|
|
672
672
|
lendingMarketOwnerCap: ObjectArg;
|
|
673
673
|
lendingMarket: ObjectArg;
|
|
674
674
|
}
|
|
675
|
+
export type ApiInterestUpdateEvent = {
|
|
676
|
+
id: number;
|
|
677
|
+
lendingMarketId: string;
|
|
678
|
+
coinType: string;
|
|
679
|
+
reserveId: string;
|
|
680
|
+
cumulativeBorrowRate: string;
|
|
681
|
+
availableAmount: string;
|
|
682
|
+
borrowedAmount: string;
|
|
683
|
+
unclaimedSpreadFees: string;
|
|
684
|
+
ctokenSupply: string;
|
|
685
|
+
borrowInterestPaid: string;
|
|
686
|
+
spreadFee: string;
|
|
687
|
+
supplyInterestEarned: string;
|
|
688
|
+
borrowInterestPaidUsdEstimate: string;
|
|
689
|
+
protocolFeeUsdEstimate: string;
|
|
690
|
+
supplyInterestEarnedUsdEstimate: string;
|
|
691
|
+
timestamp: number;
|
|
692
|
+
digest: string;
|
|
693
|
+
eventIndex: number;
|
|
694
|
+
sender: string;
|
|
695
|
+
};
|
|
675
696
|
export type ApiReserveAssetDataEvent = {
|
|
676
697
|
id: number;
|
|
677
698
|
lendingMarketId: string;
|
|
@@ -698,3 +719,146 @@ export type ApiReserveAssetDataEvent = {
|
|
|
698
719
|
export type DownsampledApiReserveAssetDataEvent = ApiReserveAssetDataEvent & {
|
|
699
720
|
sampletimestamp: number;
|
|
700
721
|
};
|
|
722
|
+
export type ApiMintEvent = {
|
|
723
|
+
id: number;
|
|
724
|
+
lendingMarketId: string;
|
|
725
|
+
coinType: string;
|
|
726
|
+
reserveId: string;
|
|
727
|
+
liquidityAmount: string;
|
|
728
|
+
ctokenAmount: string;
|
|
729
|
+
timestamp: number;
|
|
730
|
+
digest: string;
|
|
731
|
+
eventIndex: number;
|
|
732
|
+
sender: string;
|
|
733
|
+
};
|
|
734
|
+
export type ApiRedeemEvent = {
|
|
735
|
+
id: number;
|
|
736
|
+
lendingMarketId: string;
|
|
737
|
+
coinType: string;
|
|
738
|
+
reserveId: string;
|
|
739
|
+
ctokenAmount: string;
|
|
740
|
+
liquidityAmount: string;
|
|
741
|
+
timestamp: number;
|
|
742
|
+
digest: string;
|
|
743
|
+
eventIndex: number;
|
|
744
|
+
sender: string;
|
|
745
|
+
};
|
|
746
|
+
export type ApiDepositEvent = {
|
|
747
|
+
id: number;
|
|
748
|
+
lendingMarketId: string;
|
|
749
|
+
coinType: string;
|
|
750
|
+
reserveId: string;
|
|
751
|
+
obligationId: string;
|
|
752
|
+
ctokenAmount: string;
|
|
753
|
+
timestamp: number;
|
|
754
|
+
digest: string;
|
|
755
|
+
eventIndex: number;
|
|
756
|
+
sender: string;
|
|
757
|
+
};
|
|
758
|
+
export type ApiWithdrawEvent = {
|
|
759
|
+
id: number;
|
|
760
|
+
lendingMarketId: string;
|
|
761
|
+
coinType: string;
|
|
762
|
+
reserveId: string;
|
|
763
|
+
obligationId: string;
|
|
764
|
+
ctokenAmount: string;
|
|
765
|
+
timestamp: number;
|
|
766
|
+
digest: string;
|
|
767
|
+
eventIndex: number;
|
|
768
|
+
sender: string;
|
|
769
|
+
};
|
|
770
|
+
export type ApiBorrowEvent = {
|
|
771
|
+
id: number;
|
|
772
|
+
lendingMarketId: string;
|
|
773
|
+
coinType: string;
|
|
774
|
+
reserveId: string;
|
|
775
|
+
obligationId: string;
|
|
776
|
+
liquidityAmount: string;
|
|
777
|
+
originationFeeAmount: string;
|
|
778
|
+
timestamp: number;
|
|
779
|
+
digest: string;
|
|
780
|
+
eventIndex: number;
|
|
781
|
+
sender: string;
|
|
782
|
+
};
|
|
783
|
+
export type ApiRepayEvent = {
|
|
784
|
+
id: number;
|
|
785
|
+
lendingMarketId: string;
|
|
786
|
+
coinType: string;
|
|
787
|
+
reserveId: string;
|
|
788
|
+
obligationId: string;
|
|
789
|
+
liquidityAmount: string;
|
|
790
|
+
timestamp: number;
|
|
791
|
+
digest: string;
|
|
792
|
+
eventIndex: number;
|
|
793
|
+
sender: string;
|
|
794
|
+
};
|
|
795
|
+
export type ApiLiquidateEvent = {
|
|
796
|
+
id: number;
|
|
797
|
+
lendingMarketId: string;
|
|
798
|
+
repayReserveId: string;
|
|
799
|
+
withdrawReserveId: string;
|
|
800
|
+
obligationId: string;
|
|
801
|
+
repayAmount: string;
|
|
802
|
+
withdrawAmount: string;
|
|
803
|
+
protocolFeeAmount: string;
|
|
804
|
+
liquidatorBonusAmount: string;
|
|
805
|
+
timestamp: number;
|
|
806
|
+
digest: string;
|
|
807
|
+
eventIndex: number;
|
|
808
|
+
sender: string;
|
|
809
|
+
};
|
|
810
|
+
export type ApiClaimRewardEvent = {
|
|
811
|
+
id: number;
|
|
812
|
+
lendingMarketId: string;
|
|
813
|
+
reserveId: string;
|
|
814
|
+
obligationId: string;
|
|
815
|
+
isDepositReward: boolean;
|
|
816
|
+
poolRewardId: string;
|
|
817
|
+
coinType: string;
|
|
818
|
+
liquidityAmount: string;
|
|
819
|
+
timestamp: number;
|
|
820
|
+
digest: string;
|
|
821
|
+
eventIndex: number;
|
|
822
|
+
sender: string;
|
|
823
|
+
};
|
|
824
|
+
export type ApiObligationDataEvent = {
|
|
825
|
+
id: number;
|
|
826
|
+
lendingMarketId: string;
|
|
827
|
+
obligationId: string;
|
|
828
|
+
depositedValueUsd: string;
|
|
829
|
+
allowedBorrowValueUsd: string;
|
|
830
|
+
unhealthyBorrowValueUsd: string;
|
|
831
|
+
superUnhealthyBorrowValueUsd: string;
|
|
832
|
+
unweightedBorrowedValueUsd: string;
|
|
833
|
+
weightedBorrowedValueUsd: string;
|
|
834
|
+
weightedBorrowedValueUpperBoundUsd: string;
|
|
835
|
+
borrowingIsolatedAsset: boolean;
|
|
836
|
+
badDebtUsd: string;
|
|
837
|
+
closable: boolean;
|
|
838
|
+
timestamp: number;
|
|
839
|
+
digest: string;
|
|
840
|
+
eventIndex: number;
|
|
841
|
+
sender: string;
|
|
842
|
+
/**
|
|
843
|
+
* {
|
|
844
|
+
* coin_type: TypeName;
|
|
845
|
+
* reserve_array_index: u64;
|
|
846
|
+
* deposited_ctoken_amount: u64;
|
|
847
|
+
* market_value: Decimal;
|
|
848
|
+
* user_reward_manager_index: u64;
|
|
849
|
+
* attributed_borrow_value: Decimal;
|
|
850
|
+
* }[]
|
|
851
|
+
*/
|
|
852
|
+
depositsJson: string;
|
|
853
|
+
/**
|
|
854
|
+
* {
|
|
855
|
+
* coin_type: TypeName;
|
|
856
|
+
* reserve_array_index: u64;
|
|
857
|
+
* borrowed_amount: Decimal;
|
|
858
|
+
* cumulative_borrow_rate: Decimal;
|
|
859
|
+
* market_value: Decimal;
|
|
860
|
+
* user_reward_manager_index: u64;
|
|
861
|
+
* }[]
|
|
862
|
+
*/
|
|
863
|
+
borrowsJson: string;
|
|
864
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { SuiClient, SuiEvent } from "@mysten/sui.js/client";
|
|
2
|
+
type TypeName = {
|
|
3
|
+
name: string;
|
|
4
|
+
};
|
|
5
|
+
type Decimal = {
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
type address = string;
|
|
9
|
+
type u64 = string;
|
|
10
|
+
export declare enum SuilendEventType {
|
|
11
|
+
InterestUpdateEvent = "InterestUpdateEvent",
|
|
12
|
+
ReserveAssetDataEvent = "ReserveAssetDataEvent",
|
|
13
|
+
MintEvent = "MintEvent",
|
|
14
|
+
RedeemEvent = "RedeemEvent",
|
|
15
|
+
DepositEvent = "DepositEvent",
|
|
16
|
+
WithdrawEvent = "WithdrawEvent",
|
|
17
|
+
BorrowEvent = "BorrowEvent",
|
|
18
|
+
RepayEvent = "RepayEvent",
|
|
19
|
+
LiquidateEvent = "LiquidateEvent",
|
|
20
|
+
ClaimRewardEvent = "ClaimRewardEvent",
|
|
21
|
+
ObligationDataEvent = "ObligationDataEvent"
|
|
22
|
+
}
|
|
23
|
+
export declare enum SuilendTransactionModule {
|
|
24
|
+
LendingMarket = "lending_market",
|
|
25
|
+
Reserve = "reserve"
|
|
26
|
+
}
|
|
27
|
+
declare class TypedParamsSuiEvent<T> {
|
|
28
|
+
event: SuiEvent;
|
|
29
|
+
constructor(event: SuiEvent);
|
|
30
|
+
params(): T;
|
|
31
|
+
isType(module: SuilendTransactionModule, eventType: SuilendEventType): boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare class GenericSuilendEvent extends TypedParamsSuiEvent<{}> {
|
|
34
|
+
}
|
|
35
|
+
export declare class InterestUpdateEvent extends TypedParamsSuiEvent<{
|
|
36
|
+
lending_market_id: address;
|
|
37
|
+
coin_type: TypeName;
|
|
38
|
+
reserve_id: address;
|
|
39
|
+
cumulative_borrow_rate: Decimal;
|
|
40
|
+
available_amount: u64;
|
|
41
|
+
borrowed_amount: Decimal;
|
|
42
|
+
unclaimed_spread_fees: Decimal;
|
|
43
|
+
ctoken_supply: u64;
|
|
44
|
+
borrow_interest_paid: Decimal;
|
|
45
|
+
spread_fee: Decimal;
|
|
46
|
+
supply_interest_earned: Decimal;
|
|
47
|
+
borrow_interest_paid_usd_estimate: Decimal;
|
|
48
|
+
protocol_fee_usd_estimate: Decimal;
|
|
49
|
+
supply_interest_earned_usd_estimate: Decimal;
|
|
50
|
+
}> {
|
|
51
|
+
}
|
|
52
|
+
export declare class ReserveAssetDataEvent extends TypedParamsSuiEvent<{
|
|
53
|
+
lending_market_id: address;
|
|
54
|
+
coin_type: TypeName;
|
|
55
|
+
reserve_id: address;
|
|
56
|
+
available_amount: Decimal;
|
|
57
|
+
supply_amount: Decimal;
|
|
58
|
+
borrowed_amount: Decimal;
|
|
59
|
+
available_amount_usd_estimate: Decimal;
|
|
60
|
+
supply_amount_usd_estimate: Decimal;
|
|
61
|
+
borrowed_amount_usd_estimate: Decimal;
|
|
62
|
+
borrow_apr: Decimal;
|
|
63
|
+
supply_apr: Decimal;
|
|
64
|
+
ctoken_supply: u64;
|
|
65
|
+
cumulative_borrow_rate: Decimal;
|
|
66
|
+
price: Decimal;
|
|
67
|
+
smoothed_price: Decimal;
|
|
68
|
+
price_last_update_timestamp_s: u64;
|
|
69
|
+
}> {
|
|
70
|
+
}
|
|
71
|
+
export declare class MintEvent extends TypedParamsSuiEvent<{
|
|
72
|
+
lending_market_id: address;
|
|
73
|
+
coin_type: TypeName;
|
|
74
|
+
reserve_id: address;
|
|
75
|
+
liquidity_amount: u64;
|
|
76
|
+
ctoken_amount: u64;
|
|
77
|
+
}> {
|
|
78
|
+
}
|
|
79
|
+
export declare class RedeemEvent extends TypedParamsSuiEvent<{
|
|
80
|
+
lending_market_id: address;
|
|
81
|
+
coin_type: TypeName;
|
|
82
|
+
reserve_id: address;
|
|
83
|
+
ctoken_amount: u64;
|
|
84
|
+
liquidity_amount: u64;
|
|
85
|
+
}> {
|
|
86
|
+
}
|
|
87
|
+
export declare class DepositEvent extends TypedParamsSuiEvent<{
|
|
88
|
+
lending_market_id: address;
|
|
89
|
+
coin_type: TypeName;
|
|
90
|
+
reserve_id: address;
|
|
91
|
+
obligation_id: address;
|
|
92
|
+
ctoken_amount: u64;
|
|
93
|
+
}> {
|
|
94
|
+
}
|
|
95
|
+
export declare class WithdrawEvent extends TypedParamsSuiEvent<{
|
|
96
|
+
lending_market_id: address;
|
|
97
|
+
coin_type: TypeName;
|
|
98
|
+
reserve_id: address;
|
|
99
|
+
obligation_id: address;
|
|
100
|
+
ctoken_amount: u64;
|
|
101
|
+
}> {
|
|
102
|
+
}
|
|
103
|
+
export declare class BorrowEvent extends TypedParamsSuiEvent<{
|
|
104
|
+
lending_market_id: address;
|
|
105
|
+
coin_type: TypeName;
|
|
106
|
+
reserve_id: address;
|
|
107
|
+
obligation_id: address;
|
|
108
|
+
liquidity_amount: u64;
|
|
109
|
+
origination_fee_amount: u64;
|
|
110
|
+
}> {
|
|
111
|
+
}
|
|
112
|
+
export declare class RepayEvent extends TypedParamsSuiEvent<{
|
|
113
|
+
lending_market_id: address;
|
|
114
|
+
coin_type: TypeName;
|
|
115
|
+
reserve_id: address;
|
|
116
|
+
obligation_id: address;
|
|
117
|
+
liquidity_amount: u64;
|
|
118
|
+
}> {
|
|
119
|
+
}
|
|
120
|
+
export declare class LiquidateEvent extends TypedParamsSuiEvent<{
|
|
121
|
+
lending_market_id: address;
|
|
122
|
+
repay_reserve_id: address;
|
|
123
|
+
withdraw_reserve_id: address;
|
|
124
|
+
obligation_id: address;
|
|
125
|
+
repay_coin_type: TypeName;
|
|
126
|
+
withdraw_coin_type: TypeName;
|
|
127
|
+
repay_amount: u64;
|
|
128
|
+
withdraw_amount: u64;
|
|
129
|
+
protocol_fee_amount: u64;
|
|
130
|
+
liquidator_bonus_amount: u64;
|
|
131
|
+
}> {
|
|
132
|
+
}
|
|
133
|
+
export declare class ClaimRewardEvent extends TypedParamsSuiEvent<{
|
|
134
|
+
lending_market_id: address;
|
|
135
|
+
reserve_id: address;
|
|
136
|
+
obligation_id: address;
|
|
137
|
+
is_deposit_reward: boolean;
|
|
138
|
+
pool_reward_id: address;
|
|
139
|
+
coin_type: TypeName;
|
|
140
|
+
liquidity_amount: u64;
|
|
141
|
+
}> {
|
|
142
|
+
}
|
|
143
|
+
export declare class ObligationDataEvent extends TypedParamsSuiEvent<{
|
|
144
|
+
lending_market_id: address;
|
|
145
|
+
obligation_id: address;
|
|
146
|
+
deposits: {
|
|
147
|
+
coin_type: TypeName;
|
|
148
|
+
reserve_array_index: u64;
|
|
149
|
+
deposited_ctoken_amount: u64;
|
|
150
|
+
market_value: Decimal;
|
|
151
|
+
user_reward_manager_index: u64;
|
|
152
|
+
attributed_borrow_value: Decimal;
|
|
153
|
+
}[];
|
|
154
|
+
borrows: {
|
|
155
|
+
coin_type: TypeName;
|
|
156
|
+
reserve_array_index: u64;
|
|
157
|
+
borrowed_amount: Decimal;
|
|
158
|
+
cumulative_borrow_rate: Decimal;
|
|
159
|
+
market_value: Decimal;
|
|
160
|
+
user_reward_manager_index: u64;
|
|
161
|
+
}[];
|
|
162
|
+
deposited_value_usd: Decimal;
|
|
163
|
+
allowed_borrow_value_usd: Decimal;
|
|
164
|
+
unhealthy_borrow_value_usd: Decimal;
|
|
165
|
+
super_unhealthy_borrow_value_usd: Decimal;
|
|
166
|
+
unweighted_borrowed_value_usd: Decimal;
|
|
167
|
+
weighted_borrowed_value_usd: Decimal;
|
|
168
|
+
weighted_borrowed_value_upper_bound_usd: Decimal;
|
|
169
|
+
borrowing_isolated_asset: boolean;
|
|
170
|
+
bad_debt_usd: Decimal;
|
|
171
|
+
closable: boolean;
|
|
172
|
+
}> {
|
|
173
|
+
}
|
|
174
|
+
export declare function getEvents(client: SuiClient, digest: string): Promise<GenericSuilendEvent[]>;
|
|
175
|
+
export declare function getRedeemEvent(client: SuiClient, digest: string): Promise<RedeemEvent | null>;
|
|
176
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getRedeemEvent = exports.getEvents = exports.ObligationDataEvent = exports.ClaimRewardEvent = exports.LiquidateEvent = exports.RepayEvent = exports.BorrowEvent = exports.WithdrawEvent = exports.DepositEvent = exports.RedeemEvent = exports.MintEvent = exports.ReserveAssetDataEvent = exports.InterestUpdateEvent = exports.GenericSuilendEvent = exports.SuilendTransactionModule = exports.SuilendEventType = void 0;
|
|
13
|
+
var SuilendEventType;
|
|
14
|
+
(function (SuilendEventType) {
|
|
15
|
+
SuilendEventType["InterestUpdateEvent"] = "InterestUpdateEvent";
|
|
16
|
+
SuilendEventType["ReserveAssetDataEvent"] = "ReserveAssetDataEvent";
|
|
17
|
+
SuilendEventType["MintEvent"] = "MintEvent";
|
|
18
|
+
SuilendEventType["RedeemEvent"] = "RedeemEvent";
|
|
19
|
+
SuilendEventType["DepositEvent"] = "DepositEvent";
|
|
20
|
+
SuilendEventType["WithdrawEvent"] = "WithdrawEvent";
|
|
21
|
+
SuilendEventType["BorrowEvent"] = "BorrowEvent";
|
|
22
|
+
SuilendEventType["RepayEvent"] = "RepayEvent";
|
|
23
|
+
SuilendEventType["LiquidateEvent"] = "LiquidateEvent";
|
|
24
|
+
SuilendEventType["ClaimRewardEvent"] = "ClaimRewardEvent";
|
|
25
|
+
SuilendEventType["ObligationDataEvent"] = "ObligationDataEvent";
|
|
26
|
+
})(SuilendEventType || (exports.SuilendEventType = SuilendEventType = {}));
|
|
27
|
+
var SuilendTransactionModule;
|
|
28
|
+
(function (SuilendTransactionModule) {
|
|
29
|
+
SuilendTransactionModule["LendingMarket"] = "lending_market";
|
|
30
|
+
SuilendTransactionModule["Reserve"] = "reserve";
|
|
31
|
+
})(SuilendTransactionModule || (exports.SuilendTransactionModule = SuilendTransactionModule = {}));
|
|
32
|
+
class TypedParamsSuiEvent {
|
|
33
|
+
constructor(event) {
|
|
34
|
+
this.event = event;
|
|
35
|
+
}
|
|
36
|
+
params() {
|
|
37
|
+
return this.event.parsedJson;
|
|
38
|
+
}
|
|
39
|
+
isType(module, eventType) {
|
|
40
|
+
return this.event.type.includes(`${module}::${eventType}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
class GenericSuilendEvent extends TypedParamsSuiEvent {
|
|
44
|
+
}
|
|
45
|
+
exports.GenericSuilendEvent = GenericSuilendEvent;
|
|
46
|
+
class InterestUpdateEvent extends TypedParamsSuiEvent {
|
|
47
|
+
}
|
|
48
|
+
exports.InterestUpdateEvent = InterestUpdateEvent;
|
|
49
|
+
class ReserveAssetDataEvent extends TypedParamsSuiEvent {
|
|
50
|
+
}
|
|
51
|
+
exports.ReserveAssetDataEvent = ReserveAssetDataEvent;
|
|
52
|
+
class MintEvent extends TypedParamsSuiEvent {
|
|
53
|
+
}
|
|
54
|
+
exports.MintEvent = MintEvent;
|
|
55
|
+
class RedeemEvent extends TypedParamsSuiEvent {
|
|
56
|
+
}
|
|
57
|
+
exports.RedeemEvent = RedeemEvent;
|
|
58
|
+
class DepositEvent extends TypedParamsSuiEvent {
|
|
59
|
+
}
|
|
60
|
+
exports.DepositEvent = DepositEvent;
|
|
61
|
+
class WithdrawEvent extends TypedParamsSuiEvent {
|
|
62
|
+
}
|
|
63
|
+
exports.WithdrawEvent = WithdrawEvent;
|
|
64
|
+
class BorrowEvent extends TypedParamsSuiEvent {
|
|
65
|
+
}
|
|
66
|
+
exports.BorrowEvent = BorrowEvent;
|
|
67
|
+
class RepayEvent extends TypedParamsSuiEvent {
|
|
68
|
+
}
|
|
69
|
+
exports.RepayEvent = RepayEvent;
|
|
70
|
+
class LiquidateEvent extends TypedParamsSuiEvent {
|
|
71
|
+
}
|
|
72
|
+
exports.LiquidateEvent = LiquidateEvent;
|
|
73
|
+
class ClaimRewardEvent extends TypedParamsSuiEvent {
|
|
74
|
+
}
|
|
75
|
+
exports.ClaimRewardEvent = ClaimRewardEvent;
|
|
76
|
+
class ObligationDataEvent extends TypedParamsSuiEvent {
|
|
77
|
+
}
|
|
78
|
+
exports.ObligationDataEvent = ObligationDataEvent;
|
|
79
|
+
function getEvents(client, digest) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
const tx = yield client.getTransactionBlock({
|
|
82
|
+
digest,
|
|
83
|
+
options: { showEvents: true },
|
|
84
|
+
});
|
|
85
|
+
const events = [];
|
|
86
|
+
for (const event of tx.events || []) {
|
|
87
|
+
events.push(new GenericSuilendEvent(event));
|
|
88
|
+
}
|
|
89
|
+
return events;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
exports.getEvents = getEvents;
|
|
93
|
+
function getRedeemEvent(client, digest) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const events = yield getEvents(client, digest);
|
|
96
|
+
for (const event of events) {
|
|
97
|
+
if (event.isType(SuilendTransactionModule.LendingMarket, SuilendEventType.RedeemEvent)) {
|
|
98
|
+
return event;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
exports.getRedeemEvent = getRedeemEvent;
|