@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
|
@@ -1,144 +1 @@
|
|
|
1
|
-
|
|
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 function addressToString(addr: address): string;
|
|
11
|
-
export declare function u64ToNumber(value: u64): number;
|
|
12
|
-
export declare function typeNameToString(value: TypeName): string;
|
|
13
|
-
export declare function decimalToNumber(value: Decimal): number;
|
|
14
|
-
export declare enum SuilendEventType {
|
|
15
|
-
MintEvent = "MintEvent",
|
|
16
|
-
RedeemEvent = "RedeemEvent",
|
|
17
|
-
DepositEvent = "DepositEvent",
|
|
18
|
-
WithdrawEvent = "WithdrawEvent",
|
|
19
|
-
BorrowEvent = "BorrowEvent",
|
|
20
|
-
RepayEvent = "RepayEvent",
|
|
21
|
-
LiquidateEvent = "LiquidateEvent",
|
|
22
|
-
InterestUpdateEvent = "InterestUpdateEvent",
|
|
23
|
-
ReserveAssetDataEvent = "ReserveAssetDataEvent"
|
|
24
|
-
}
|
|
25
|
-
export declare enum SuilendTransactionModule {
|
|
26
|
-
LendingMarket = "lending_market",
|
|
27
|
-
Reserve = "reserve"
|
|
28
|
-
}
|
|
29
|
-
declare class TypedParamsSuiEvent<T> {
|
|
30
|
-
event: SuiEvent;
|
|
31
|
-
constructor(event: SuiEvent);
|
|
32
|
-
params(): T;
|
|
33
|
-
isType(module: SuilendTransactionModule, eventType: SuilendEventType): boolean;
|
|
34
|
-
}
|
|
35
|
-
export declare class GenericSuilendEvent extends TypedParamsSuiEvent<{}> {
|
|
36
|
-
}
|
|
37
|
-
export declare class InterestUpdateEvent extends TypedParamsSuiEvent<{
|
|
38
|
-
lending_market: TypeName;
|
|
39
|
-
coin_type: TypeName;
|
|
40
|
-
reserve_id: address;
|
|
41
|
-
cumulative_borrow_rate: Decimal;
|
|
42
|
-
available_amount: u64;
|
|
43
|
-
borrowed_amount: Decimal;
|
|
44
|
-
unclaimed_spread_fees: Decimal;
|
|
45
|
-
ctoken_supply: u64;
|
|
46
|
-
borrow_interest_paid: Decimal;
|
|
47
|
-
spread_fee: Decimal;
|
|
48
|
-
supply_interest_earned: Decimal;
|
|
49
|
-
borrow_interest_paid_usd_estimate: Decimal;
|
|
50
|
-
protocol_fee_usd_estimate: Decimal;
|
|
51
|
-
supply_interest_earned_usd_estimate: Decimal;
|
|
52
|
-
}> {
|
|
53
|
-
}
|
|
54
|
-
export declare class ReserveAssetDataEvent extends TypedParamsSuiEvent<{
|
|
55
|
-
lending_market: TypeName;
|
|
56
|
-
coin_type: TypeName;
|
|
57
|
-
reserve_id: address;
|
|
58
|
-
available_amount: Decimal;
|
|
59
|
-
supply_amount: Decimal;
|
|
60
|
-
borrowed_amount: Decimal;
|
|
61
|
-
available_amount_usd_estimate: Decimal;
|
|
62
|
-
supply_amount_usd_estimate: Decimal;
|
|
63
|
-
borrowed_amount_usd_estimate: Decimal;
|
|
64
|
-
borrow_apr: Decimal;
|
|
65
|
-
supply_apr: Decimal;
|
|
66
|
-
ctoken_supply: u64;
|
|
67
|
-
cumulative_borrow_rate: Decimal;
|
|
68
|
-
price: Decimal;
|
|
69
|
-
smoothed_price: Decimal;
|
|
70
|
-
price_last_update_timestamp_s: u64;
|
|
71
|
-
}> {
|
|
72
|
-
}
|
|
73
|
-
export declare class MintEvent extends TypedParamsSuiEvent<{
|
|
74
|
-
lending_market: TypeName;
|
|
75
|
-
coin_type: TypeName;
|
|
76
|
-
reserve_id: address;
|
|
77
|
-
liquidity_amount: u64;
|
|
78
|
-
ctoken_amount: u64;
|
|
79
|
-
}> {
|
|
80
|
-
}
|
|
81
|
-
export declare class RedeemEvent extends TypedParamsSuiEvent<{
|
|
82
|
-
lending_market: TypeName;
|
|
83
|
-
coin_type: TypeName;
|
|
84
|
-
reserve_id: address;
|
|
85
|
-
ctoken_amount: u64;
|
|
86
|
-
liquidity_amount: u64;
|
|
87
|
-
}> {
|
|
88
|
-
}
|
|
89
|
-
export declare class DepositEvent extends TypedParamsSuiEvent<{
|
|
90
|
-
lending_market: TypeName;
|
|
91
|
-
coin_type: TypeName;
|
|
92
|
-
reserve_id: address;
|
|
93
|
-
obligation_id: address;
|
|
94
|
-
ctoken_amount: u64;
|
|
95
|
-
}> {
|
|
96
|
-
}
|
|
97
|
-
export declare class WithdrawEvent extends TypedParamsSuiEvent<{
|
|
98
|
-
lending_market: TypeName;
|
|
99
|
-
coin_type: TypeName;
|
|
100
|
-
reserve_id: address;
|
|
101
|
-
obligation_id: address;
|
|
102
|
-
ctoken_amount: u64;
|
|
103
|
-
}> {
|
|
104
|
-
}
|
|
105
|
-
export declare class BorrowEvent extends TypedParamsSuiEvent<{
|
|
106
|
-
lending_market: TypeName;
|
|
107
|
-
coin_type: TypeName;
|
|
108
|
-
reserve_id: address;
|
|
109
|
-
obligation_id: address;
|
|
110
|
-
liquidity_amount: u64;
|
|
111
|
-
}> {
|
|
112
|
-
}
|
|
113
|
-
export declare class RepayEvent extends TypedParamsSuiEvent<{
|
|
114
|
-
lending_market: TypeName;
|
|
115
|
-
coin_type: TypeName;
|
|
116
|
-
reserve_id: address;
|
|
117
|
-
obligation_id: address;
|
|
118
|
-
liquidity_amount: u64;
|
|
119
|
-
}> {
|
|
120
|
-
}
|
|
121
|
-
export declare class LiquidateEvent extends TypedParamsSuiEvent<{
|
|
122
|
-
lending_market: TypeName;
|
|
123
|
-
repay_reserve_id: address;
|
|
124
|
-
withdraw_reserve_id: address;
|
|
125
|
-
obligation_id: address;
|
|
126
|
-
repay_amount: u64;
|
|
127
|
-
withdraw_amount: u64;
|
|
128
|
-
protocol_fee_amount: u64;
|
|
129
|
-
liquidator_bonus_amount: u64;
|
|
130
|
-
}> {
|
|
131
|
-
}
|
|
132
|
-
export declare class ClaimRewardEvent extends TypedParamsSuiEvent<{
|
|
133
|
-
coin_type: TypeName;
|
|
134
|
-
is_deposit_reward: boolean;
|
|
135
|
-
lending_market_id: string;
|
|
136
|
-
liquidity_amount: string;
|
|
137
|
-
obligation_id: string;
|
|
138
|
-
pool_reward_id: string;
|
|
139
|
-
reserve_id: "0x0b8faf51e65f0beee47f6b9627108ee25b5a2b922ae7ee5725485ed7a9293523";
|
|
140
|
-
}> {
|
|
141
|
-
}
|
|
142
|
-
export declare function getEvents(client: SuiClient, digest: string): Promise<GenericSuilendEvent[]>;
|
|
143
|
-
export declare function getRedeemEvent(client: SuiClient, digest: string): Promise<RedeemEvent | null>;
|
|
144
|
-
export {};
|
|
1
|
+
export * from "../../core/utils/events";
|
package/mainnet/utils/events.js
CHANGED
|
@@ -1,115 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
10
15
|
};
|
|
11
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
13
|
-
function addressToString(addr) {
|
|
14
|
-
return addr;
|
|
15
|
-
}
|
|
16
|
-
exports.addressToString = addressToString;
|
|
17
|
-
function u64ToNumber(value) {
|
|
18
|
-
return parseInt(value);
|
|
19
|
-
}
|
|
20
|
-
exports.u64ToNumber = u64ToNumber;
|
|
21
|
-
function typeNameToString(value) {
|
|
22
|
-
return value.name;
|
|
23
|
-
}
|
|
24
|
-
exports.typeNameToString = typeNameToString;
|
|
25
|
-
function decimalToNumber(value) {
|
|
26
|
-
return parseInt(value.value) / 10 ** 18;
|
|
27
|
-
}
|
|
28
|
-
exports.decimalToNumber = decimalToNumber;
|
|
29
|
-
var SuilendEventType;
|
|
30
|
-
(function (SuilendEventType) {
|
|
31
|
-
SuilendEventType["MintEvent"] = "MintEvent";
|
|
32
|
-
SuilendEventType["RedeemEvent"] = "RedeemEvent";
|
|
33
|
-
SuilendEventType["DepositEvent"] = "DepositEvent";
|
|
34
|
-
SuilendEventType["WithdrawEvent"] = "WithdrawEvent";
|
|
35
|
-
SuilendEventType["BorrowEvent"] = "BorrowEvent";
|
|
36
|
-
SuilendEventType["RepayEvent"] = "RepayEvent";
|
|
37
|
-
SuilendEventType["LiquidateEvent"] = "LiquidateEvent";
|
|
38
|
-
SuilendEventType["InterestUpdateEvent"] = "InterestUpdateEvent";
|
|
39
|
-
SuilendEventType["ReserveAssetDataEvent"] = "ReserveAssetDataEvent";
|
|
40
|
-
})(SuilendEventType || (exports.SuilendEventType = SuilendEventType = {}));
|
|
41
|
-
var SuilendTransactionModule;
|
|
42
|
-
(function (SuilendTransactionModule) {
|
|
43
|
-
SuilendTransactionModule["LendingMarket"] = "lending_market";
|
|
44
|
-
SuilendTransactionModule["Reserve"] = "reserve";
|
|
45
|
-
})(SuilendTransactionModule || (exports.SuilendTransactionModule = SuilendTransactionModule = {}));
|
|
46
|
-
class TypedParamsSuiEvent {
|
|
47
|
-
constructor(event) {
|
|
48
|
-
this.event = event;
|
|
49
|
-
}
|
|
50
|
-
params() {
|
|
51
|
-
return this.event.parsedJson;
|
|
52
|
-
}
|
|
53
|
-
isType(module, eventType) {
|
|
54
|
-
return this.event.type.includes(`${module}::${eventType}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
class GenericSuilendEvent extends TypedParamsSuiEvent {
|
|
58
|
-
}
|
|
59
|
-
exports.GenericSuilendEvent = GenericSuilendEvent;
|
|
60
|
-
class InterestUpdateEvent extends TypedParamsSuiEvent {
|
|
61
|
-
}
|
|
62
|
-
exports.InterestUpdateEvent = InterestUpdateEvent;
|
|
63
|
-
class ReserveAssetDataEvent extends TypedParamsSuiEvent {
|
|
64
|
-
}
|
|
65
|
-
exports.ReserveAssetDataEvent = ReserveAssetDataEvent;
|
|
66
|
-
class MintEvent extends TypedParamsSuiEvent {
|
|
67
|
-
}
|
|
68
|
-
exports.MintEvent = MintEvent;
|
|
69
|
-
class RedeemEvent extends TypedParamsSuiEvent {
|
|
70
|
-
}
|
|
71
|
-
exports.RedeemEvent = RedeemEvent;
|
|
72
|
-
class DepositEvent extends TypedParamsSuiEvent {
|
|
73
|
-
}
|
|
74
|
-
exports.DepositEvent = DepositEvent;
|
|
75
|
-
class WithdrawEvent extends TypedParamsSuiEvent {
|
|
76
|
-
}
|
|
77
|
-
exports.WithdrawEvent = WithdrawEvent;
|
|
78
|
-
class BorrowEvent extends TypedParamsSuiEvent {
|
|
79
|
-
}
|
|
80
|
-
exports.BorrowEvent = BorrowEvent;
|
|
81
|
-
class RepayEvent extends TypedParamsSuiEvent {
|
|
82
|
-
}
|
|
83
|
-
exports.RepayEvent = RepayEvent;
|
|
84
|
-
class LiquidateEvent extends TypedParamsSuiEvent {
|
|
85
|
-
}
|
|
86
|
-
exports.LiquidateEvent = LiquidateEvent;
|
|
87
|
-
class ClaimRewardEvent extends TypedParamsSuiEvent {
|
|
88
|
-
}
|
|
89
|
-
exports.ClaimRewardEvent = ClaimRewardEvent;
|
|
90
|
-
function getEvents(client, digest) {
|
|
91
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
-
const tx = yield client.getTransactionBlock({
|
|
93
|
-
digest,
|
|
94
|
-
options: { showEvents: true },
|
|
95
|
-
});
|
|
96
|
-
const events = [];
|
|
97
|
-
for (const event of tx.events || []) {
|
|
98
|
-
events.push(new GenericSuilendEvent(event));
|
|
99
|
-
}
|
|
100
|
-
return events;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
exports.getEvents = getEvents;
|
|
104
|
-
function getRedeemEvent(client, digest) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const events = yield getEvents(client, digest);
|
|
107
|
-
for (const event of events) {
|
|
108
|
-
if (event.isType(SuilendTransactionModule.LendingMarket, SuilendEventType.RedeemEvent)) {
|
|
109
|
-
return event;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return null;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
exports.getRedeemEvent = getRedeemEvent;
|
|
17
|
+
__exportStar(require("../../core/utils/events"), exports);
|
|
@@ -2,15 +2,15 @@ import { SuiClient } from "@mysten/sui.js/client";
|
|
|
2
2
|
import { Obligation } from "../_generated/suilend/obligation/structs";
|
|
3
3
|
export declare function fetchAllObligationsForMarketWithHandler(client: SuiClient, marketAddress: string, chunkHandler: (obligations: Obligation<string>[]) => Promise<void>): Promise<void>;
|
|
4
4
|
export declare function fetchAllObligationsForMarket(client: SuiClient, marketAddress: string): Promise<Obligation<string>[]>;
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
5
|
+
export type FormattedObligationHistory = NonLiquidationHistoryEvent | LiquidationHistoryEvent;
|
|
6
|
+
export type NonLiquidationHistoryEvent = {
|
|
7
7
|
reserveId: string;
|
|
8
8
|
quantity: number;
|
|
9
9
|
action: string;
|
|
10
10
|
timestampMs: number;
|
|
11
11
|
digest: string;
|
|
12
12
|
};
|
|
13
|
-
export type
|
|
13
|
+
export type LiquidationHistoryEvent = {
|
|
14
14
|
repayReserveId: string;
|
|
15
15
|
repayQuantity: number;
|
|
16
16
|
withdrawReserveId: string;
|
|
@@ -21,5 +21,5 @@ export type liquidationHistoryEvent = {
|
|
|
21
21
|
};
|
|
22
22
|
export declare function getObligationHistoryPage(client: SuiClient, obligationId: string, maxQuantity: number, cursor: string | null): Promise<{
|
|
23
23
|
cursor: string | null | undefined;
|
|
24
|
-
history:
|
|
24
|
+
history: FormattedObligationHistory[];
|
|
25
25
|
}>;
|
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import { SuiPriceServiceConnection } from "../../pyth-sdk";
|
|
3
3
|
import { Decimal } from "../_generated/suilend/decimal/structs";
|
|
4
|
-
import { PoolRewardManager } from "../_generated/suilend/liquidity-mining/structs";
|
|
5
|
-
import { Obligation } from "../_generated/suilend/obligation/structs";
|
|
4
|
+
import { PoolRewardManager, UserRewardManager } from "../_generated/suilend/liquidity-mining/structs";
|
|
5
|
+
import { Borrow, Obligation } from "../_generated/suilend/obligation/structs";
|
|
6
6
|
import { Reserve } from "../_generated/suilend/reserve/structs";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare
|
|
11
|
-
export declare
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export declare
|
|
16
|
-
export declare
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated since version 1.0.8. Use `calculateUtilizationPercent` instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare const calculateUtilizationRate: (reserve: Reserve<string>) => BigNumber;
|
|
11
|
+
export declare const calculateUtilizationPercent: (reserve: Reserve<string>) => BigNumber;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated since version 1.0.8. Use `calculateBorrowAprPercent` instead.
|
|
14
|
+
*/
|
|
15
|
+
export declare const calculateBorrowApr: (reserve: Reserve<string>) => BigNumber;
|
|
16
|
+
export declare const calculateBorrowAprPercent: (reserve: Reserve<string>) => BigNumber;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated since version 1.0.8. Use `calculateDepositAprPercent` instead.
|
|
19
|
+
*/
|
|
20
|
+
export declare const calculateSupplyApr: (reserve: Reserve<string>) => BigNumber;
|
|
21
|
+
export declare const calculateDepositAprPercent: (reserve: Reserve<string>) => BigNumber;
|
|
22
|
+
export declare const compoundReserveInterest: (reserve: Reserve<string>, now: number) => Reserve<string>;
|
|
23
|
+
export declare const updatePoolRewardsManager: (manager: PoolRewardManager, nowMs: number) => PoolRewardManager;
|
|
24
|
+
export declare const refreshReservePrice: (reserves: Reserve<string>[], pythConnection: SuiPriceServiceConnection) => Promise<Reserve<string>[]>;
|
|
25
|
+
export declare const updateUserRewardManager: (poolManager: PoolRewardManager, userRewardManager: UserRewardManager, now: number) => UserRewardManager;
|
|
26
|
+
export declare const refreshObligation: (unrefreshedObligation: Obligation<string>, refreshedReserves: Reserve<string>[]) => Obligation<string>;
|
|
27
|
+
export declare const numberToDecimal: (value: number) => Decimal;
|
|
28
|
+
export declare const stringToDecimal: (value: string) => Decimal;
|
|
29
|
+
export declare const decimalToBigNumber: (value: Decimal) => BigNumber;
|
|
30
|
+
export declare const getCTokenMarketValue: (reserve: Reserve<string>, depositedCTokenAmount: BigNumber) => BigNumber;
|
|
31
|
+
export declare const getCTokenMarketValueLowerBound: (reserve: Reserve<string>, depositedCTokenAmount: BigNumber) => BigNumber;
|
|
32
|
+
export declare const cTokenRatio: (reserve: Reserve<string>) => BigNumber;
|
|
33
|
+
export declare const totalSupply: (reserve: Reserve<string>) => BigNumber;
|
|
34
|
+
export declare const compoundDebt: (borrow: Borrow, reserve: Reserve<string>) => Borrow;
|