@suilend/sdk 1.1.37 → 1.1.39
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/_generated/suilend/index.d.ts +1 -0
- package/_generated/suilend/index.js +10 -7
- package/_generated/suilend/lending-market/functions.d.ts +8 -0
- package/_generated/suilend/lending-market/functions.js +21 -0
- package/_generated/suilend/lending-market/structs.d.ts +2 -2
- package/_generated/suilend/obligation/structs.d.ts +43 -1
- package/_generated/suilend/obligation/structs.js +128 -1
- package/client.d.ts +17 -2
- package/client.js +50 -9
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +2 -3
- package/lib/initialize.d.ts +21 -15
- package/lib/initialize.js +47 -39
- package/lib/liquidityMining.d.ts +2 -2
- package/lib/liquidityMining.js +15 -17
- package/package.json +1 -1
- package/parsers/lendingMarket.d.ts +4 -1
- package/parsers/lendingMarket.js +13 -2
- package/parsers/rateLimiter.d.ts +1 -1
- package/parsers/rateLimiter.js +2 -2
- package/utils/obligation.d.ts +2 -2
- package/utils/obligation.js +6 -7
- package/utils/simulate.d.ts +2 -2
- package/utils/simulate.js +7 -7
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PKG_V10 = exports.PKG_V8 = exports.PKG_V1 = exports.PUBLISHED_AT = exports.PACKAGE_ID = void 0;
|
|
3
|
+
exports.PKG_V11 = exports.PKG_V10 = exports.PKG_V8 = exports.PKG_V1 = exports.PUBLISHED_AT = exports.PACKAGE_ID = void 0;
|
|
4
4
|
exports.setPublishedAt = setPublishedAt;
|
|
5
|
-
exports.PACKAGE_ID = process.env.
|
|
5
|
+
exports.PACKAGE_ID = process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
6
6
|
? "0x1f54a9a2d71799553197e9ea24557797c6398d6a65f2d4d3818c9304b75d5e21"
|
|
7
7
|
: "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
8
|
-
exports.PUBLISHED_AT = process.env.
|
|
9
|
-
? "
|
|
8
|
+
exports.PUBLISHED_AT = process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
9
|
+
? "0x5bb8cb3894945f523736f4f5059b1621056e8093b165ea56b20805d0ef2461a9"
|
|
10
10
|
: "0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444";
|
|
11
|
-
exports.PKG_V1 = process.env.
|
|
11
|
+
exports.PKG_V1 = process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
12
12
|
? "0x1f54a9a2d71799553197e9ea24557797c6398d6a65f2d4d3818c9304b75d5e21"
|
|
13
13
|
: "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
14
|
-
exports.PKG_V8 = process.env.
|
|
14
|
+
exports.PKG_V8 = process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
15
15
|
? "0xe5ed361add4433f4d23e56fc0e3bacab39b93592d5e65d508e33fd19ff696669"
|
|
16
16
|
: "0x5b54b47971238403d6ade3c8c2cc75814cb55145a5184af916bb5b12aaf184cb";
|
|
17
|
-
exports.PKG_V10 = process.env.
|
|
17
|
+
exports.PKG_V10 = process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
18
18
|
? "0xe5ed361add4433f4d23e56fc0e3bacab39b93592d5e65d508e33fd19ff696669"
|
|
19
19
|
: "0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444";
|
|
20
|
+
exports.PKG_V11 = process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
21
|
+
? "0xe5ed361add4433f4d23e56fc0e3bacab39b93592d5e65d508e33fd19ff696669"
|
|
22
|
+
: "0xd2a67633ccb8de063163e25bcfca242929caf5cf1a26c2929dab519ee0b8f331";
|
|
20
23
|
function setPublishedAt(publishedAt) {
|
|
21
24
|
exports.PUBLISHED_AT = publishedAt;
|
|
22
25
|
}
|
|
@@ -16,6 +16,7 @@ export declare function init(tx: Transaction, otw: TransactionObjectInput): impo
|
|
|
16
16
|
export interface ClaimFeesArgs {
|
|
17
17
|
lendingMarket: TransactionObjectInput;
|
|
18
18
|
reserveArrayIndex: bigint | TransactionArgument;
|
|
19
|
+
systemState: TransactionObjectInput;
|
|
19
20
|
}
|
|
20
21
|
export declare function claimFees(tx: Transaction, typeArgs: [string, string], args: ClaimFeesArgs): import("@mysten/sui/transactions").TransactionResult;
|
|
21
22
|
export interface AddPoolRewardArgs {
|
|
@@ -57,6 +58,12 @@ export interface ClosePoolRewardArgs {
|
|
|
57
58
|
}
|
|
58
59
|
export declare function closePoolReward(tx: Transaction, typeArgs: [string, string], args: ClosePoolRewardArgs): import("@mysten/sui/transactions").TransactionResult;
|
|
59
60
|
export declare function reserve(tx: Transaction, typeArgs: [string, string], lendingMarket: TransactionObjectInput): import("@mysten/sui/transactions").TransactionResult;
|
|
61
|
+
export interface CompoundInterestArgs {
|
|
62
|
+
lendingMarket: TransactionObjectInput;
|
|
63
|
+
reserveArrayIndex: bigint | TransactionArgument;
|
|
64
|
+
clock: TransactionObjectInput;
|
|
65
|
+
}
|
|
66
|
+
export declare function compoundInterest(tx: Transaction, typeArg: string, args: CompoundInterestArgs): import("@mysten/sui/transactions").TransactionResult;
|
|
60
67
|
export interface DepositLiquidityAndMintCtokensArgs {
|
|
61
68
|
lendingMarket: TransactionObjectInput;
|
|
62
69
|
reserveArrayIndex: bigint | TransactionArgument;
|
|
@@ -137,6 +144,7 @@ export interface LiquidateArgs {
|
|
|
137
144
|
repayCoins: TransactionObjectInput;
|
|
138
145
|
}
|
|
139
146
|
export declare function liquidate(tx: Transaction, typeArgs: [string, string, string], args: LiquidateArgs): import("@mysten/sui/transactions").TransactionResult;
|
|
147
|
+
export declare function reserves(tx: Transaction, typeArg: string, lendingMarket: TransactionObjectInput): import("@mysten/sui/transactions").TransactionResult;
|
|
140
148
|
export interface MaxWithdrawAmountArgs {
|
|
141
149
|
rateLimiter: TransactionObjectInput;
|
|
142
150
|
obligation: TransactionObjectInput;
|
|
@@ -9,6 +9,7 @@ exports.cancelPoolReward = cancelPoolReward;
|
|
|
9
9
|
exports.claimRewards = claimRewards;
|
|
10
10
|
exports.closePoolReward = closePoolReward;
|
|
11
11
|
exports.reserve = reserve;
|
|
12
|
+
exports.compoundInterest = compoundInterest;
|
|
12
13
|
exports.depositLiquidityAndMintCtokens = depositLiquidityAndMintCtokens;
|
|
13
14
|
exports.fulfillLiquidityRequest = fulfillLiquidityRequest;
|
|
14
15
|
exports.initStaker = initStaker;
|
|
@@ -22,6 +23,7 @@ exports.createObligation = createObligation;
|
|
|
22
23
|
exports.reserveArrayIndex = reserveArrayIndex;
|
|
23
24
|
exports.forgive = forgive;
|
|
24
25
|
exports.liquidate = liquidate;
|
|
26
|
+
exports.reserves = reserves;
|
|
25
27
|
exports.maxWithdrawAmount = maxWithdrawAmount;
|
|
26
28
|
exports.repay = repay;
|
|
27
29
|
exports.obligationId = obligationId;
|
|
@@ -81,6 +83,7 @@ function claimFees(tx, typeArgs, args) {
|
|
|
81
83
|
arguments: [
|
|
82
84
|
(0, util_1.obj)(tx, args.lendingMarket),
|
|
83
85
|
(0, util_1.pure)(tx, args.reserveArrayIndex, `u64`),
|
|
86
|
+
(0, util_1.obj)(tx, args.systemState),
|
|
84
87
|
],
|
|
85
88
|
});
|
|
86
89
|
}
|
|
@@ -149,6 +152,17 @@ function reserve(tx, typeArgs, lendingMarket) {
|
|
|
149
152
|
arguments: [(0, util_1.obj)(tx, lendingMarket)],
|
|
150
153
|
});
|
|
151
154
|
}
|
|
155
|
+
function compoundInterest(tx, typeArg, args) {
|
|
156
|
+
return tx.moveCall({
|
|
157
|
+
target: `${__1.PUBLISHED_AT}::lending_market::compound_interest`,
|
|
158
|
+
typeArguments: [typeArg],
|
|
159
|
+
arguments: [
|
|
160
|
+
(0, util_1.obj)(tx, args.lendingMarket),
|
|
161
|
+
(0, util_1.pure)(tx, args.reserveArrayIndex, `u64`),
|
|
162
|
+
(0, util_1.obj)(tx, args.clock),
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
}
|
|
152
166
|
function depositLiquidityAndMintCtokens(tx, typeArgs, args) {
|
|
153
167
|
return tx.moveCall({
|
|
154
168
|
target: `${__1.PUBLISHED_AT}::lending_market::deposit_liquidity_and_mint_ctokens`,
|
|
@@ -296,6 +310,13 @@ function liquidate(tx, typeArgs, args) {
|
|
|
296
310
|
],
|
|
297
311
|
});
|
|
298
312
|
}
|
|
313
|
+
function reserves(tx, typeArg, lendingMarket) {
|
|
314
|
+
return tx.moveCall({
|
|
315
|
+
target: `${__1.PUBLISHED_AT}::lending_market::reserves`,
|
|
316
|
+
typeArguments: [typeArg],
|
|
317
|
+
arguments: [(0, util_1.obj)(tx, lendingMarket)],
|
|
318
|
+
});
|
|
319
|
+
}
|
|
299
320
|
function maxWithdrawAmount(tx, typeArg, args) {
|
|
300
321
|
return tx.moveCall({
|
|
301
322
|
target: `${__1.PUBLISHED_AT}::lending_market::max_withdraw_amount`,
|
|
@@ -452,7 +452,7 @@ export declare class FeeReceivers implements StructClass {
|
|
|
452
452
|
static reified(): FeeReceiversReified;
|
|
453
453
|
static get r(): reified.StructClassReified<FeeReceivers, FeeReceiversFields>;
|
|
454
454
|
static phantom(): PhantomReified<ToTypeStr<FeeReceivers>>;
|
|
455
|
-
static get p(): reified.PhantomReified<"
|
|
455
|
+
static get p(): reified.PhantomReified<"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444::lending_market::FeeReceivers" | "0xe5ed361add4433f4d23e56fc0e3bacab39b93592d5e65d508e33fd19ff696669::lending_market::FeeReceivers">;
|
|
456
456
|
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
457
457
|
receivers: string[];
|
|
458
458
|
weights: string[];
|
|
@@ -506,7 +506,7 @@ export declare class FeeReceiversKey implements StructClass {
|
|
|
506
506
|
static reified(): FeeReceiversKeyReified;
|
|
507
507
|
static get r(): reified.StructClassReified<FeeReceiversKey, FeeReceiversKeyFields>;
|
|
508
508
|
static phantom(): PhantomReified<ToTypeStr<FeeReceiversKey>>;
|
|
509
|
-
static get p(): reified.PhantomReified<"
|
|
509
|
+
static get p(): reified.PhantomReified<"0xe37cc7bb50fd9b6dbd3873df66fa2c554e973697f50ef97707311dc78bd08444::lending_market::FeeReceiversKey" | "0xe5ed361add4433f4d23e56fc0e3bacab39b93592d5e65d508e33fd19ff696669::lending_market::FeeReceiversKey">;
|
|
510
510
|
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
511
511
|
dummy_field: boolean;
|
|
512
512
|
}, {
|
|
@@ -5,7 +5,7 @@ import { PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructC
|
|
|
5
5
|
import { FieldsWithTypes } from "../../_framework/util";
|
|
6
6
|
import { Vector } from "../../_framework/vector";
|
|
7
7
|
import { Decimal } from "../decimal/structs";
|
|
8
|
-
import { PKG_V1 } from "../index";
|
|
8
|
+
import { PKG_V1, PKG_V11 } from "../index";
|
|
9
9
|
import { UserRewardManager } from "../liquidity-mining/structs";
|
|
10
10
|
import { SuiClient, SuiObjectData, SuiParsedData } from "@mysten/sui/client";
|
|
11
11
|
export declare function isBorrow(type: string): boolean;
|
|
@@ -432,6 +432,48 @@ export declare class DepositRecord implements StructClass {
|
|
|
432
432
|
static fromSuiObjectData(data: SuiObjectData): DepositRecord;
|
|
433
433
|
static fetch(client: SuiClient, id: string): Promise<DepositRecord>;
|
|
434
434
|
}
|
|
435
|
+
export declare function isExistStaleOracles(type: string): boolean;
|
|
436
|
+
export interface ExistStaleOraclesFields {
|
|
437
|
+
dummyField: ToField<"bool">;
|
|
438
|
+
}
|
|
439
|
+
export type ExistStaleOraclesReified = Reified<ExistStaleOracles, ExistStaleOraclesFields>;
|
|
440
|
+
export declare class ExistStaleOracles implements StructClass {
|
|
441
|
+
__StructClass: true;
|
|
442
|
+
static readonly $typeName: string;
|
|
443
|
+
static readonly $numTypeParams = 0;
|
|
444
|
+
static readonly $isPhantom: readonly [];
|
|
445
|
+
readonly $typeName: string;
|
|
446
|
+
readonly $fullTypeName: `${typeof PKG_V11}::obligation::ExistStaleOracles`;
|
|
447
|
+
readonly $typeArgs: [];
|
|
448
|
+
readonly $isPhantom: readonly [];
|
|
449
|
+
readonly dummyField: ToField<"bool">;
|
|
450
|
+
private constructor();
|
|
451
|
+
static reified(): ExistStaleOraclesReified;
|
|
452
|
+
static get r(): reified.StructClassReified<ExistStaleOracles, ExistStaleOraclesFields>;
|
|
453
|
+
static phantom(): PhantomReified<ToTypeStr<ExistStaleOracles>>;
|
|
454
|
+
static get p(): reified.PhantomReified<"0xe5ed361add4433f4d23e56fc0e3bacab39b93592d5e65d508e33fd19ff696669::obligation::ExistStaleOracles" | "0xd2a67633ccb8de063163e25bcfca242929caf5cf1a26c2929dab519ee0b8f331::obligation::ExistStaleOracles">;
|
|
455
|
+
static get bcs(): import("@mysten/sui/bcs").BcsType<{
|
|
456
|
+
dummy_field: boolean;
|
|
457
|
+
}, {
|
|
458
|
+
dummy_field: boolean;
|
|
459
|
+
}>;
|
|
460
|
+
static fromFields(fields: Record<string, any>): ExistStaleOracles;
|
|
461
|
+
static fromFieldsWithTypes(item: FieldsWithTypes): ExistStaleOracles;
|
|
462
|
+
static fromBcs(data: Uint8Array): ExistStaleOracles;
|
|
463
|
+
toJSONField(): {
|
|
464
|
+
dummyField: boolean;
|
|
465
|
+
};
|
|
466
|
+
toJSON(): {
|
|
467
|
+
dummyField: boolean;
|
|
468
|
+
$typeName: string;
|
|
469
|
+
$typeArgs: [];
|
|
470
|
+
};
|
|
471
|
+
static fromJSONField(field: any): ExistStaleOracles;
|
|
472
|
+
static fromJSON(json: Record<string, any>): ExistStaleOracles;
|
|
473
|
+
static fromSuiParsedData(content: SuiParsedData): ExistStaleOracles;
|
|
474
|
+
static fromSuiObjectData(data: SuiObjectData): ExistStaleOracles;
|
|
475
|
+
static fetch(client: SuiClient, id: string): Promise<ExistStaleOracles>;
|
|
476
|
+
}
|
|
435
477
|
export declare function isObligation(type: string): boolean;
|
|
436
478
|
export interface ObligationFields<P extends PhantomTypeArgument> {
|
|
437
479
|
id: ToField<UID>;
|
|
@@ -42,11 +42,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.ObligationDataEvent = exports.Obligation = exports.DepositRecord = exports.Deposit = exports.BorrowRecord = exports.Borrow = void 0;
|
|
45
|
+
exports.ObligationDataEvent = exports.Obligation = exports.ExistStaleOracles = exports.DepositRecord = exports.Deposit = exports.BorrowRecord = exports.Borrow = void 0;
|
|
46
46
|
exports.isBorrow = isBorrow;
|
|
47
47
|
exports.isBorrowRecord = isBorrowRecord;
|
|
48
48
|
exports.isDeposit = isDeposit;
|
|
49
49
|
exports.isDepositRecord = isDepositRecord;
|
|
50
|
+
exports.isExistStaleOracles = isExistStaleOracles;
|
|
50
51
|
exports.isObligation = isObligation;
|
|
51
52
|
exports.isObligationDataEvent = isObligationDataEvent;
|
|
52
53
|
const reified = __importStar(require("../../_framework/reified"));
|
|
@@ -681,6 +682,132 @@ exports.DepositRecord = DepositRecord;
|
|
|
681
682
|
DepositRecord.$typeName = `${index_1.PKG_V1}::obligation::DepositRecord`;
|
|
682
683
|
DepositRecord.$numTypeParams = 0;
|
|
683
684
|
DepositRecord.$isPhantom = [];
|
|
685
|
+
/* ============================== ExistStaleOracles =============================== */
|
|
686
|
+
function isExistStaleOracles(type) {
|
|
687
|
+
type = (0, util_1.compressSuiType)(type);
|
|
688
|
+
return type === `${index_1.PKG_V11}::obligation::ExistStaleOracles`;
|
|
689
|
+
}
|
|
690
|
+
class ExistStaleOracles {
|
|
691
|
+
constructor(typeArgs, fields) {
|
|
692
|
+
this.__StructClass = true;
|
|
693
|
+
this.$typeName = ExistStaleOracles.$typeName;
|
|
694
|
+
this.$isPhantom = ExistStaleOracles.$isPhantom;
|
|
695
|
+
this.$fullTypeName = (0, util_1.composeSuiType)(ExistStaleOracles.$typeName, ...typeArgs);
|
|
696
|
+
this.$typeArgs = typeArgs;
|
|
697
|
+
this.dummyField = fields.dummyField;
|
|
698
|
+
}
|
|
699
|
+
static reified() {
|
|
700
|
+
return {
|
|
701
|
+
typeName: ExistStaleOracles.$typeName,
|
|
702
|
+
fullTypeName: (0, util_1.composeSuiType)(ExistStaleOracles.$typeName, ...[]),
|
|
703
|
+
typeArgs: [],
|
|
704
|
+
isPhantom: ExistStaleOracles.$isPhantom,
|
|
705
|
+
reifiedTypeArgs: [],
|
|
706
|
+
fromFields: (fields) => ExistStaleOracles.fromFields(fields),
|
|
707
|
+
fromFieldsWithTypes: (item) => ExistStaleOracles.fromFieldsWithTypes(item),
|
|
708
|
+
fromBcs: (data) => ExistStaleOracles.fromBcs(data),
|
|
709
|
+
bcs: ExistStaleOracles.bcs,
|
|
710
|
+
fromJSONField: (field) => ExistStaleOracles.fromJSONField(field),
|
|
711
|
+
fromJSON: (json) => ExistStaleOracles.fromJSON(json),
|
|
712
|
+
fromSuiParsedData: (content) => ExistStaleOracles.fromSuiParsedData(content),
|
|
713
|
+
fromSuiObjectData: (content) => ExistStaleOracles.fromSuiObjectData(content),
|
|
714
|
+
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return ExistStaleOracles.fetch(client, id); }),
|
|
715
|
+
new: (fields) => {
|
|
716
|
+
return new ExistStaleOracles([], fields);
|
|
717
|
+
},
|
|
718
|
+
kind: "StructClassReified",
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
static get r() {
|
|
722
|
+
return ExistStaleOracles.reified();
|
|
723
|
+
}
|
|
724
|
+
static phantom() {
|
|
725
|
+
return (0, reified_1.phantom)(ExistStaleOracles.reified());
|
|
726
|
+
}
|
|
727
|
+
static get p() {
|
|
728
|
+
return ExistStaleOracles.phantom();
|
|
729
|
+
}
|
|
730
|
+
static get bcs() {
|
|
731
|
+
return bcs_1.bcs.struct("ExistStaleOracles", {
|
|
732
|
+
dummy_field: bcs_1.bcs.bool(),
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
static fromFields(fields) {
|
|
736
|
+
return ExistStaleOracles.reified().new({
|
|
737
|
+
dummyField: (0, reified_1.decodeFromFields)("bool", fields.dummy_field),
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
static fromFieldsWithTypes(item) {
|
|
741
|
+
if (!isExistStaleOracles(item.type)) {
|
|
742
|
+
throw new Error("not a ExistStaleOracles type");
|
|
743
|
+
}
|
|
744
|
+
return ExistStaleOracles.reified().new({
|
|
745
|
+
dummyField: (0, reified_1.decodeFromFieldsWithTypes)("bool", item.fields.dummy_field),
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
static fromBcs(data) {
|
|
749
|
+
return ExistStaleOracles.fromFields(ExistStaleOracles.bcs.parse(data));
|
|
750
|
+
}
|
|
751
|
+
toJSONField() {
|
|
752
|
+
return {
|
|
753
|
+
dummyField: this.dummyField,
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
toJSON() {
|
|
757
|
+
return Object.assign({ $typeName: this.$typeName, $typeArgs: this.$typeArgs }, this.toJSONField());
|
|
758
|
+
}
|
|
759
|
+
static fromJSONField(field) {
|
|
760
|
+
return ExistStaleOracles.reified().new({
|
|
761
|
+
dummyField: (0, reified_1.decodeFromJSONField)("bool", field.dummyField),
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
static fromJSON(json) {
|
|
765
|
+
if (json.$typeName !== ExistStaleOracles.$typeName) {
|
|
766
|
+
throw new Error("not a WithTwoGenerics json object");
|
|
767
|
+
}
|
|
768
|
+
return ExistStaleOracles.fromJSONField(json);
|
|
769
|
+
}
|
|
770
|
+
static fromSuiParsedData(content) {
|
|
771
|
+
if (content.dataType !== "moveObject") {
|
|
772
|
+
throw new Error("not an object");
|
|
773
|
+
}
|
|
774
|
+
if (!isExistStaleOracles(content.type)) {
|
|
775
|
+
throw new Error(`object at ${content.fields.id} is not a ExistStaleOracles object`);
|
|
776
|
+
}
|
|
777
|
+
return ExistStaleOracles.fromFieldsWithTypes(content);
|
|
778
|
+
}
|
|
779
|
+
static fromSuiObjectData(data) {
|
|
780
|
+
if (data.bcs) {
|
|
781
|
+
if (data.bcs.dataType !== "moveObject" ||
|
|
782
|
+
!isExistStaleOracles(data.bcs.type)) {
|
|
783
|
+
throw new Error(`object at is not a ExistStaleOracles object`);
|
|
784
|
+
}
|
|
785
|
+
return ExistStaleOracles.fromBcs((0, utils_1.fromB64)(data.bcs.bcsBytes));
|
|
786
|
+
}
|
|
787
|
+
if (data.content) {
|
|
788
|
+
return ExistStaleOracles.fromSuiParsedData(data.content);
|
|
789
|
+
}
|
|
790
|
+
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
791
|
+
}
|
|
792
|
+
static fetch(client, id) {
|
|
793
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
794
|
+
var _a, _b;
|
|
795
|
+
const res = yield client.getObject({ id, options: { showBcs: true } });
|
|
796
|
+
if (res.error) {
|
|
797
|
+
throw new Error(`error fetching ExistStaleOracles object at id ${id}: ${res.error.code}`);
|
|
798
|
+
}
|
|
799
|
+
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
800
|
+
!isExistStaleOracles(res.data.bcs.type)) {
|
|
801
|
+
throw new Error(`object at id ${id} is not a ExistStaleOracles object`);
|
|
802
|
+
}
|
|
803
|
+
return ExistStaleOracles.fromSuiObjectData(res.data);
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
exports.ExistStaleOracles = ExistStaleOracles;
|
|
808
|
+
ExistStaleOracles.$typeName = `${index_1.PKG_V11}::obligation::ExistStaleOracles`;
|
|
809
|
+
ExistStaleOracles.$numTypeParams = 0;
|
|
810
|
+
ExistStaleOracles.$isPhantom = [];
|
|
684
811
|
/* ============================== Obligation =============================== */
|
|
685
812
|
function isObligation(type) {
|
|
686
813
|
type = (0, util_1.compressSuiType)(type);
|
package/client.d.ts
CHANGED
|
@@ -6,6 +6,21 @@ import { Obligation } from "./_generated/suilend/obligation/structs";
|
|
|
6
6
|
import { NewConfigArgs as CreateRateLimiterConfigArgs } from "./_generated/suilend/rate-limiter/functions";
|
|
7
7
|
import { CreateReserveConfigArgs } from "./_generated/suilend/reserve-config/functions";
|
|
8
8
|
import { Side } from "./lib/types";
|
|
9
|
+
export declare const ADMIN_ADDRESS: string;
|
|
10
|
+
export declare const LENDING_MARKET_REGISTRY_ID: string;
|
|
11
|
+
export declare const LENDING_MARKETS: ({
|
|
12
|
+
name: string;
|
|
13
|
+
id: string;
|
|
14
|
+
type: string;
|
|
15
|
+
ownerCapId: string;
|
|
16
|
+
isHidden?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
name: string;
|
|
19
|
+
id: string;
|
|
20
|
+
type: string;
|
|
21
|
+
ownerCapId: string;
|
|
22
|
+
isHidden: boolean;
|
|
23
|
+
})[];
|
|
9
24
|
export declare const LENDING_MARKET_ID: string;
|
|
10
25
|
export declare const LENDING_MARKET_TYPE: string;
|
|
11
26
|
export type ClaimRewardsReward = {
|
|
@@ -29,8 +44,8 @@ export declare class SuilendClient {
|
|
|
29
44
|
static getObligationOwnerCaps(ownerId: string, lendingMarketTypeArgs: string[], client: SuiClient): Promise<ObligationOwnerCap<string>[]>;
|
|
30
45
|
static getObligation(obligationId: string, lendingMarketTypeArgs: string[], client: SuiClient): Promise<Obligation<string>>;
|
|
31
46
|
getObligation(obligationId: string): Promise<Obligation<string>>;
|
|
32
|
-
static getLendingMarketOwnerCapId(ownerId: string, lendingMarketTypeArgs: string[], client: SuiClient): Promise<string |
|
|
33
|
-
getLendingMarketOwnerCapId(ownerId: string): Promise<string |
|
|
47
|
+
static getLendingMarketOwnerCapId(ownerId: string, lendingMarketTypeArgs: string[], client: SuiClient): Promise<string | undefined>;
|
|
48
|
+
getLendingMarketOwnerCapId(ownerId: string): Promise<string | undefined>;
|
|
34
49
|
createReserve(lendingMarketOwnerCapId: string, transaction: Transaction, pythPriceId: string, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs): Promise<TransactionResult>;
|
|
35
50
|
addReward(ownerId: string, lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardCoinType: string, rewardValue: string, startTimeMs: bigint, endTimeMs: bigint, transaction: Transaction, mergeCoins?: boolean): Promise<TransactionResult>;
|
|
36
51
|
cancelReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): TransactionResult;
|
package/client.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.SuilendClient = exports.LENDING_MARKET_TYPE = exports.LENDING_MARKET_ID = void 0;
|
|
12
|
+
exports.SuilendClient = exports.LENDING_MARKET_TYPE = exports.LENDING_MARKET_ID = exports.LENDING_MARKETS = exports.LENDING_MARKET_REGISTRY_ID = exports.ADMIN_ADDRESS = void 0;
|
|
13
13
|
const utils_1 = require("@mysten/sui/utils");
|
|
14
14
|
const pyth_sui_js_1 = require("@pythnetwork/pyth-sui-js");
|
|
15
15
|
const frontend_sui_1 = require("@suilend/frontend-sui");
|
|
@@ -29,15 +29,55 @@ const NORMALIZED_SUI_COINTYPE = (0, utils_1.normalizeStructTag)(SUI_COINTYPE);
|
|
|
29
29
|
const isSui = (coinType) => (0, utils_1.normalizeStructTag)(coinType) === NORMALIZED_SUI_COINTYPE;
|
|
30
30
|
const WORMHOLE_STATE_ID = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
|
|
31
31
|
const PYTH_STATE_ID = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
|
|
32
|
-
|
|
32
|
+
exports.ADMIN_ADDRESS = process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
33
|
+
? "0xa902504c338e17f44dfee1bd1c3cad1ff03326579b9cdcfe2762fc12c46fc033" // beta owner
|
|
34
|
+
: "0xb1ffbc2e1915f44b8f271a703becc1bf8aa79bc22431a58900a102892b783c25";
|
|
35
|
+
const SUILEND_UPGRADE_CAP_ID = process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
33
36
|
? "0x05da14368a42a351e106806c09727968ae26be77a6741a018239ef0f99d5185e"
|
|
34
37
|
: "0x3d4ef1859c3ee9fc72858f588b56a09da5466e64f8cc4e90a7b3b909fba8a7ae";
|
|
35
|
-
exports.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
exports.LENDING_MARKET_REGISTRY_ID = process.env
|
|
39
|
+
.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
40
|
+
? "0x925c9a2336b02fc2b68099837bd66f6b5b4d45cd460e0a4b81708bac6c440eff"
|
|
41
|
+
: "0x64faff8d91a56c4f55debbb44767b009ee744a70bc2cc8e3bbd2718c92f85931";
|
|
42
|
+
exports.LENDING_MARKETS = process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET
|
|
43
|
+
? [
|
|
44
|
+
// {
|
|
45
|
+
// name: "Old",
|
|
46
|
+
// id: "0x850850ef3ec0aa8c3345a2c3c486b571fdc31f3ebcaff931d7f9b9707aace2f8",
|
|
47
|
+
// type: "0x2::sui::SUI",
|
|
48
|
+
// ownerCapId:
|
|
49
|
+
// "0xa92aae3be305687d3abe36deb4d92f78ec17bfce7d8d07972722d1166e4bc6ab",
|
|
50
|
+
// },
|
|
51
|
+
{
|
|
52
|
+
name: "Main market",
|
|
53
|
+
id: "0x12e46de3eafaf0308a2dd64f1158782ed19e6621835bf883a1dd6b3061115667",
|
|
54
|
+
type: "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI",
|
|
55
|
+
ownerCapId: "0xf0df3204ecd426bc83f5e5dccb07ea35f1af220a40ec02dfd63fb7f2fea00824",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "Isolated 1",
|
|
59
|
+
id: "0xb1d89cf9082cedce09d3647f0ebda4a8b5db125aff5d312a8bfd7eefa715bd35",
|
|
60
|
+
type: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",
|
|
61
|
+
ownerCapId: "0xed8262012d34105c5ac59cf2dd6473d492e6ab7529fe7f9ea6cb1fa8dc2dba56",
|
|
62
|
+
isHidden: true, // FOR TESTING ONLY
|
|
63
|
+
},
|
|
64
|
+
]
|
|
65
|
+
: [
|
|
66
|
+
{
|
|
67
|
+
name: "Main market",
|
|
68
|
+
id: "0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1",
|
|
69
|
+
type: "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL",
|
|
70
|
+
ownerCapId: "0xf7a4defe0b6566b6a2674a02a0c61c9f99bd012eed21bc741a069eaa82d35927",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "STEAMM LP",
|
|
74
|
+
id: "0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",
|
|
75
|
+
type: "0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",
|
|
76
|
+
ownerCapId: "0x55a0f33b24e091830302726c8cfbff8cf8abd2ec1f83a4e6f4bf51c7ba3ad5ab",
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
exports.LENDING_MARKET_ID = exports.LENDING_MARKETS[0].id; // Main market, for backwards compatibility
|
|
80
|
+
exports.LENDING_MARKET_TYPE = exports.LENDING_MARKETS[0].type; // Main market, for backwards compatibility
|
|
41
81
|
function getLatestPackageId(client, upgradeCapId) {
|
|
42
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
83
|
var _a;
|
|
@@ -162,7 +202,7 @@ class SuilendClient {
|
|
|
162
202
|
if (objs.data.length > 0)
|
|
163
203
|
return (_a = objs.data[0].data) === null || _a === void 0 ? void 0 : _a.objectId;
|
|
164
204
|
else
|
|
165
|
-
return
|
|
205
|
+
return undefined;
|
|
166
206
|
});
|
|
167
207
|
}
|
|
168
208
|
getLendingMarketOwnerCapId(ownerId) {
|
|
@@ -608,6 +648,7 @@ class SuilendClient {
|
|
|
608
648
|
return (0, functions_1.claimFees)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
609
649
|
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
610
650
|
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
651
|
+
systemState: transaction.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID),
|
|
611
652
|
});
|
|
612
653
|
}
|
|
613
654
|
setFeeReceiversAndWeights(transaction, lendingMarketOwnerCapId, receivers, weights) {
|
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
|
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.msPerYear = exports.WAD =
|
|
6
|
+
exports.msPerYear = exports.WAD = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
-
exports.maxU64 = new bignumber_js_1.default(2).pow(64).minus(1);
|
|
9
8
|
exports.WAD = new bignumber_js_1.default(10).pow(18);
|
|
10
|
-
exports.msPerYear = 31556952000; // Approx. 1000 * 60 * 60 * 24 * 365;
|
|
9
|
+
exports.msPerYear = 31556952000; // Approx. 1000 * 60 * 60 * 24 * 365; // Used by external dependencies (e.g. msafe-sui-app-store)
|
package/lib/initialize.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
+
import { Reserve } from "../_generated/suilend/reserve/structs";
|
|
3
4
|
import { SuilendClient } from "../client";
|
|
4
|
-
import {
|
|
5
|
+
import { ParsedReserve } from "../parsers";
|
|
5
6
|
export declare const RESERVES_CUSTOM_ORDER: string[];
|
|
6
|
-
export declare const initializeSuilend: (suiClient: SuiClient, suilendClient: SuilendClient
|
|
7
|
+
export declare const initializeSuilend: (suiClient: SuiClient, suilendClient: SuilendClient) => Promise<{
|
|
7
8
|
lendingMarket: {
|
|
8
9
|
id: string;
|
|
10
|
+
type: string;
|
|
9
11
|
version: bigint;
|
|
10
12
|
reserves: {
|
|
11
13
|
config: {
|
|
@@ -133,10 +135,15 @@ export declare const initializeSuilend: (suiClient: SuiClient, suilendClient: Su
|
|
|
133
135
|
depositedAmountUsd: BigNumber;
|
|
134
136
|
borrowedAmountUsd: BigNumber;
|
|
135
137
|
tvlUsd: BigNumber;
|
|
138
|
+
name: string;
|
|
139
|
+
ownerCapId: string;
|
|
136
140
|
totalSupplyUsd: BigNumber;
|
|
137
141
|
totalBorrowUsd: BigNumber;
|
|
138
142
|
};
|
|
139
|
-
|
|
143
|
+
coinMetadataMap: {
|
|
144
|
+
[x: string]: import("@mysten/sui/client").CoinMetadata;
|
|
145
|
+
};
|
|
146
|
+
refreshedRawReserves: Reserve<string>[];
|
|
140
147
|
reserveMap: Record<string, {
|
|
141
148
|
config: {
|
|
142
149
|
$typeName: string;
|
|
@@ -246,13 +253,16 @@ export declare const initializeSuilend: (suiClient: SuiClient, suilendClient: Su
|
|
|
246
253
|
totalDeposits: BigNumber;
|
|
247
254
|
}>;
|
|
248
255
|
reserveCoinTypes: string[];
|
|
256
|
+
reserveCoinMetadataMap: Record<string, import("@mysten/sui/client").CoinMetadata>;
|
|
249
257
|
rewardCoinTypes: string[];
|
|
250
|
-
|
|
251
|
-
rewardCoinMetadataMap: Record<string, CoinMetadata>;
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
258
|
+
activeRewardCoinTypes: string[];
|
|
259
|
+
rewardCoinMetadataMap: Record<string, import("@mysten/sui/client").CoinMetadata>;
|
|
260
|
+
}>;
|
|
261
|
+
export declare const initializeSuilendRewards: (reserveMap: Record<string, ParsedReserve>, activeRewardCoinTypes: string[]) => Promise<{
|
|
262
|
+
rewardPriceMap: Record<string, BigNumber | undefined>;
|
|
263
|
+
}>;
|
|
264
|
+
export declare const initializeObligations: (suiClient: SuiClient, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>, address?: string) => Promise<{
|
|
265
|
+
obligationOwnerCaps: import("../_generated/suilend/lending-market/structs").ObligationOwnerCap<string>[];
|
|
256
266
|
obligations: {
|
|
257
267
|
id: string;
|
|
258
268
|
depositedAmountUsd: BigNumber;
|
|
@@ -509,9 +519,5 @@ export declare const initializeSuilend: (suiClient: SuiClient, suilendClient: Su
|
|
|
509
519
|
maxPriceTotalWeightedBorrowUsd: BigNumber;
|
|
510
520
|
borrowLimit: BigNumber;
|
|
511
521
|
minPriceBorrowLimit: BigNumber;
|
|
512
|
-
}[]
|
|
513
|
-
}>;
|
|
514
|
-
export declare const initializeSuilendRewards: (reserveMap: Record<string, ParsedReserve>, rewardCoinTypes: string[], rewardCoinMetadataMap: Record<string, CoinMetadata>, obligations?: ParsedObligation[]) => Promise<{
|
|
515
|
-
rewardPriceMap: Record<string, BigNumber | undefined>;
|
|
516
|
-
rewardMap: import("./liquidityMining").RewardMap;
|
|
522
|
+
}[];
|
|
517
523
|
}>;
|
package/lib/initialize.js
CHANGED
|
@@ -45,7 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.initializeSuilendRewards = exports.initializeSuilend = exports.RESERVES_CUSTOM_ORDER = void 0;
|
|
48
|
+
exports.initializeObligations = exports.initializeSuilendRewards = exports.initializeSuilend = exports.RESERVES_CUSTOM_ORDER = void 0;
|
|
49
49
|
const utils_1 = require("@mysten/sui/utils");
|
|
50
50
|
const pyth_sui_js_1 = require("@pythnetwork/pyth-sui-js");
|
|
51
51
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
@@ -54,11 +54,10 @@ const client_1 = require("../client");
|
|
|
54
54
|
const parsers_1 = require("../parsers");
|
|
55
55
|
const simulate = __importStar(require("../utils/simulate"));
|
|
56
56
|
const constants_1 = require("./constants");
|
|
57
|
-
const liquidityMining_1 = require("./liquidityMining");
|
|
58
57
|
exports.RESERVES_CUSTOM_ORDER = [
|
|
59
|
-
//
|
|
58
|
+
// MAIN ASSETS
|
|
60
59
|
frontend_sui_1.NORMALIZED_sSUI_COINTYPE,
|
|
61
|
-
//
|
|
60
|
+
// MAIN ASSETS - Ecosystem LSTs
|
|
62
61
|
frontend_sui_1.NORMALIZED_mSUI_COINTYPE,
|
|
63
62
|
frontend_sui_1.NORMALIZED_fudSUI_COINTYPE,
|
|
64
63
|
frontend_sui_1.NORMALIZED_kSUI_COINTYPE,
|
|
@@ -67,29 +66,32 @@ exports.RESERVES_CUSTOM_ORDER = [
|
|
|
67
66
|
frontend_sui_1.NORMALIZED_SUI_COINTYPE,
|
|
68
67
|
frontend_sui_1.NORMALIZED_USDC_COINTYPE,
|
|
69
68
|
frontend_sui_1.NORMALIZED_suiUSDT_COINTYPE,
|
|
70
|
-
frontend_sui_1.NORMALIZED_wUSDT_COINTYPE,
|
|
71
69
|
frontend_sui_1.NORMALIZED_AUSD_COINTYPE,
|
|
70
|
+
frontend_sui_1.NORMALIZED_wBTC_COINTYPE,
|
|
72
71
|
frontend_sui_1.NORMALIZED_suiETH_COINTYPE,
|
|
73
72
|
frontend_sui_1.NORMALIZED_SOL_COINTYPE,
|
|
74
|
-
//
|
|
73
|
+
// ISOLATED ASSETS
|
|
75
74
|
frontend_sui_1.NORMALIZED_SEND_COINTYPE,
|
|
76
75
|
frontend_sui_1.NORMALIZED_DEEP_COINTYPE,
|
|
77
|
-
frontend_sui_1.NORMALIZED_BLUE_COINTYPE,
|
|
76
|
+
frontend_sui_1.NORMALIZED_BLUE_COINTYPE,
|
|
78
77
|
frontend_sui_1.NORMALIZED_NS_COINTYPE,
|
|
79
78
|
frontend_sui_1.NORMALIZED_BUCK_COINTYPE,
|
|
80
|
-
//
|
|
79
|
+
// ISOLATED ASSETS - Memecoins
|
|
81
80
|
frontend_sui_1.NORMALIZED_HIPPO_COINTYPE,
|
|
82
81
|
frontend_sui_1.NORMALIZED_LOFI_COINTYPE, // Not listed
|
|
83
82
|
frontend_sui_1.NORMALIZED_FUD_COINTYPE,
|
|
84
|
-
//
|
|
83
|
+
// DEPRECATED ASSETS
|
|
85
84
|
frontend_sui_1.NORMALIZED_wUSDC_COINTYPE,
|
|
85
|
+
frontend_sui_1.NORMALIZED_wUSDT_COINTYPE,
|
|
86
86
|
frontend_sui_1.NORMALIZED_WETH_COINTYPE,
|
|
87
87
|
];
|
|
88
|
-
const initializeSuilend = (suiClient, suilendClient
|
|
89
|
-
const
|
|
90
|
-
const
|
|
88
|
+
const initializeSuilend = (suiClient, suilendClient) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const nowMs = Date.now();
|
|
90
|
+
const nowS = Math.floor(nowMs / 1000);
|
|
91
|
+
const refreshedRawReserves = yield simulate.refreshReservePrice(suilendClient.lendingMarket.reserves.map((r) => simulate.compoundReserveInterest(r, nowS)), new pyth_sui_js_1.SuiPriceServiceConnection("https://hermes.pyth.network"));
|
|
91
92
|
const reserveCoinTypes = [];
|
|
92
93
|
const rewardCoinTypes = [];
|
|
94
|
+
const activeRewardCoinTypes = [];
|
|
93
95
|
refreshedRawReserves.forEach((r) => {
|
|
94
96
|
reserveCoinTypes.push((0, utils_1.normalizeStructTag)(r.coinType.name));
|
|
95
97
|
[
|
|
@@ -98,13 +100,19 @@ const initializeSuilend = (suiClient, suilendClient, address) => __awaiter(void
|
|
|
98
100
|
].forEach((pr) => {
|
|
99
101
|
if (!pr)
|
|
100
102
|
return;
|
|
103
|
+
const isActive = nowMs >= Number(pr.startTimeMs) && nowMs < Number(pr.endTimeMs);
|
|
101
104
|
rewardCoinTypes.push((0, utils_1.normalizeStructTag)(pr.coinType.name));
|
|
105
|
+
if (isActive)
|
|
106
|
+
activeRewardCoinTypes.push((0, utils_1.normalizeStructTag)(pr.coinType.name));
|
|
102
107
|
});
|
|
103
108
|
});
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
const rewardCoinMetadataMap = yield
|
|
109
|
+
const uniqueReserveCoinTypes = Array.from(new Set(reserveCoinTypes));
|
|
110
|
+
const uniqueRewardCoinTypes = Array.from(new Set(rewardCoinTypes));
|
|
111
|
+
const uniqueActiveRewardsCoinTypes = Array.from(new Set(activeRewardCoinTypes));
|
|
112
|
+
const [reserveCoinMetadataMap, rewardCoinMetadataMap] = yield Promise.all([
|
|
113
|
+
(0, frontend_sui_1.getCoinMetadataMap)(suiClient, uniqueReserveCoinTypes),
|
|
114
|
+
(0, frontend_sui_1.getCoinMetadataMap)(suiClient, uniqueRewardCoinTypes),
|
|
115
|
+
]);
|
|
108
116
|
const coinMetadataMap = Object.assign(Object.assign({}, reserveCoinMetadataMap), rewardCoinMetadataMap);
|
|
109
117
|
const reservesWithTemporaryPythPriceFeeds = refreshedRawReserves.filter((r) => frontend_sui_1.TEMPORARY_PYTH_PRICE_FEED_COINTYPES.includes((0, utils_1.normalizeStructTag)(r.coinType.name)));
|
|
110
118
|
for (const reserve of reservesWithTemporaryPythPriceFeeds) {
|
|
@@ -117,7 +125,7 @@ const initializeSuilend = (suiClient, suilendClient, address) => __awaiter(void
|
|
|
117
125
|
reserve.price.value = parsedBirdeyePrice;
|
|
118
126
|
reserve.smoothedPrice.value = parsedBirdeyePrice;
|
|
119
127
|
}
|
|
120
|
-
const lendingMarket = (0, parsers_1.parseLendingMarket)(suilendClient.lendingMarket, refreshedRawReserves, coinMetadataMap,
|
|
128
|
+
const lendingMarket = (0, parsers_1.parseLendingMarket)(suilendClient.lendingMarket, refreshedRawReserves, coinMetadataMap, nowS);
|
|
121
129
|
lendingMarket.reserves = lendingMarket.reserves.slice().sort((a, b) => {
|
|
122
130
|
const aCustomOrderIndex = exports.RESERVES_CUSTOM_ORDER.indexOf(a.coinType);
|
|
123
131
|
const bCustomOrderIndex = exports.RESERVES_CUSTOM_ORDER.indexOf(b.coinType);
|
|
@@ -129,42 +137,42 @@ const initializeSuilend = (suiClient, suilendClient, address) => __awaiter(void
|
|
|
129
137
|
return aCustomOrderIndex > -1 ? -1 : 1;
|
|
130
138
|
});
|
|
131
139
|
const reserveMap = lendingMarket.reserves.reduce((acc, reserve) => (Object.assign(Object.assign({}, acc), { [reserve.coinType]: reserve })), {});
|
|
132
|
-
// Obligations
|
|
133
|
-
let obligationOwnerCaps, obligations;
|
|
134
|
-
if (address) {
|
|
135
|
-
obligationOwnerCaps = yield client_1.SuilendClient.getObligationOwnerCaps(address, suilendClient.lendingMarket.$typeArgs, suiClient);
|
|
136
|
-
obligations = (yield Promise.all(obligationOwnerCaps.map((ownerCap) => client_1.SuilendClient.getObligation(ownerCap.obligationId, suilendClient.lendingMarket.$typeArgs, suiClient))))
|
|
137
|
-
.map((rawObligation) => simulate.refreshObligation(rawObligation, refreshedRawReserves))
|
|
138
|
-
.map((refreshedObligation) => (0, parsers_1.parseObligation)(refreshedObligation, reserveMap))
|
|
139
|
-
.sort((a, b) => +b.netValueUsd.minus(a.netValueUsd));
|
|
140
|
-
}
|
|
141
140
|
return {
|
|
142
141
|
lendingMarket,
|
|
142
|
+
coinMetadataMap,
|
|
143
143
|
refreshedRawReserves,
|
|
144
144
|
reserveMap,
|
|
145
|
-
reserveCoinTypes:
|
|
146
|
-
rewardCoinTypes: uniqueRewardsCoinTypes,
|
|
145
|
+
reserveCoinTypes: uniqueReserveCoinTypes,
|
|
147
146
|
reserveCoinMetadataMap,
|
|
147
|
+
rewardCoinTypes: uniqueRewardCoinTypes,
|
|
148
|
+
activeRewardCoinTypes: uniqueActiveRewardsCoinTypes,
|
|
148
149
|
rewardCoinMetadataMap,
|
|
149
|
-
coinMetadataMap,
|
|
150
|
-
obligationOwnerCaps,
|
|
151
|
-
obligations,
|
|
152
150
|
};
|
|
153
151
|
});
|
|
154
152
|
exports.initializeSuilend = initializeSuilend;
|
|
155
|
-
const initializeSuilendRewards = (reserveMap,
|
|
153
|
+
const initializeSuilendRewards = (reserveMap, activeRewardCoinTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
154
|
const rewardPriceMap = Object.entries(reserveMap).reduce((acc, [coinType, reserve]) => (Object.assign(Object.assign({}, acc), { [coinType]: reserve.price })), {});
|
|
157
155
|
rewardPriceMap[frontend_sui_1.NORMALIZED_TREATS_COINTYPE] = new bignumber_js_1.default(0.1);
|
|
158
|
-
const
|
|
156
|
+
const reservelessActiveRewardCoinTypes = activeRewardCoinTypes.filter((coinType) => !((0, frontend_sui_1.isSendPoints)(coinType) || coinType === frontend_sui_1.NORMALIZED_MAYA_COINTYPE) &&
|
|
159
157
|
!rewardPriceMap[coinType]);
|
|
160
|
-
const
|
|
161
|
-
for (let i = 0; i <
|
|
162
|
-
const birdeyePrice =
|
|
158
|
+
const reservelessActiveRewardBirdeyePrices = yield Promise.all(reservelessActiveRewardCoinTypes.map((coinType) => (0, frontend_sui_1.getPrice)(coinType)));
|
|
159
|
+
for (let i = 0; i < reservelessActiveRewardCoinTypes.length; i++) {
|
|
160
|
+
const birdeyePrice = reservelessActiveRewardBirdeyePrices[i];
|
|
163
161
|
if (birdeyePrice === undefined)
|
|
164
162
|
continue;
|
|
165
|
-
rewardPriceMap[
|
|
163
|
+
rewardPriceMap[reservelessActiveRewardCoinTypes[i]] = new bignumber_js_1.default(birdeyePrice);
|
|
166
164
|
}
|
|
167
|
-
|
|
168
|
-
return { rewardPriceMap, rewardMap };
|
|
165
|
+
return { rewardPriceMap };
|
|
169
166
|
});
|
|
170
167
|
exports.initializeSuilendRewards = initializeSuilendRewards;
|
|
168
|
+
const initializeObligations = (suiClient, suilendClient, refreshedRawReserves, reserveMap, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
169
|
+
if (!address)
|
|
170
|
+
return { obligationOwnerCaps: [], obligations: [] };
|
|
171
|
+
const obligationOwnerCaps = yield client_1.SuilendClient.getObligationOwnerCaps(address, suilendClient.lendingMarket.$typeArgs, suiClient);
|
|
172
|
+
const obligations = (yield Promise.all(obligationOwnerCaps.map((ownerCap) => client_1.SuilendClient.getObligation(ownerCap.obligationId, suilendClient.lendingMarket.$typeArgs, suiClient))))
|
|
173
|
+
.map((rawObligation) => simulate.refreshObligation(rawObligation, refreshedRawReserves))
|
|
174
|
+
.map((refreshedObligation) => (0, parsers_1.parseObligation)(refreshedObligation, reserveMap))
|
|
175
|
+
.sort((a, b) => +b.netValueUsd.minus(a.netValueUsd));
|
|
176
|
+
return { obligationOwnerCaps, obligations };
|
|
177
|
+
});
|
|
178
|
+
exports.initializeObligations = initializeObligations;
|
package/lib/liquidityMining.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { ParsedObligation, ParsedReserve } from "../parsers";
|
|
|
4
4
|
import { Side } from "./types";
|
|
5
5
|
export type RewardMap = {
|
|
6
6
|
[coinType: string]: {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
[Side.DEPOSIT]: RewardSummary[];
|
|
8
|
+
[Side.BORROW]: RewardSummary[];
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
type ObligationClaim = {
|
package/lib/liquidityMining.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getNetAprPercent = exports.getTotalAprPercent = exports.getStakingYieldAprPercent = exports.getDedupedPerDayRewards = exports.getDedupedAprRewards = exports.getFilteredRewards = exports.formatRewards = exports.getBorrowShare = exports.getDepositShare = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
8
|
const lodash_1 = require("lodash");
|
|
9
|
+
const frontend_sui_1 = require("@suilend/frontend-sui");
|
|
9
10
|
const constants_1 = require("./constants");
|
|
10
11
|
const types_1 = require("./types");
|
|
11
12
|
const getDepositShare = (reserve, share) => share.div(10 ** reserve.mintDecimals).times(reserve.cTokenExchangeRate);
|
|
@@ -15,18 +16,16 @@ const getBorrowShare = (reserve, share) => share.div(10 ** reserve.mintDecimals)
|
|
|
15
16
|
exports.getBorrowShare = getBorrowShare;
|
|
16
17
|
const getBorrowShareUsd = (reserve, share) => (0, exports.getBorrowShare)(reserve, share).times(reserve.price);
|
|
17
18
|
const formatRewards = (parsedReserveMap, coinMetadataMap, priceMap, obligations) => {
|
|
18
|
-
const
|
|
19
|
+
const nowMs = Date.now();
|
|
19
20
|
const rewardMap = {};
|
|
20
21
|
const getRewardSummary = (reserve, poolReward, side) => {
|
|
21
|
-
var _a;
|
|
22
22
|
const rewardCoinMetadata = coinMetadataMap[poolReward.coinType];
|
|
23
23
|
const rewardPrice = priceMap === null || priceMap === void 0 ? void 0 : priceMap[poolReward.coinType];
|
|
24
|
-
const isActive =
|
|
25
|
-
currentTime < poolReward.endTimeMs;
|
|
24
|
+
const isActive = nowMs >= poolReward.startTimeMs && nowMs < poolReward.endTimeMs;
|
|
26
25
|
const aprPercent = rewardPrice
|
|
27
26
|
? poolReward.totalRewards
|
|
28
27
|
.times(rewardPrice)
|
|
29
|
-
.times(new bignumber_js_1.default(
|
|
28
|
+
.times(new bignumber_js_1.default(frontend_sui_1.MS_PER_YEAR).div(poolReward.endTimeMs - poolReward.startTimeMs))
|
|
30
29
|
.div(side === types_1.Side.DEPOSIT
|
|
31
30
|
? getDepositShareUsd(reserve, new bignumber_js_1.default(reserve.depositsPoolRewardManager.totalShares.toString()))
|
|
32
31
|
: getBorrowShareUsd(reserve, new bignumber_js_1.default(reserve.borrowsPoolRewardManager.totalShares.toString())))
|
|
@@ -35,7 +34,7 @@ const formatRewards = (parsedReserveMap, coinMetadataMap, priceMap, obligations)
|
|
|
35
34
|
const perDay = rewardPrice
|
|
36
35
|
? undefined
|
|
37
36
|
: poolReward.totalRewards
|
|
38
|
-
.times(new bignumber_js_1.default(
|
|
37
|
+
.times(new bignumber_js_1.default(frontend_sui_1.MS_PER_YEAR).div(poolReward.endTimeMs - poolReward.startTimeMs))
|
|
39
38
|
.div(365)
|
|
40
39
|
.div(side === types_1.Side.DEPOSIT
|
|
41
40
|
? (0, exports.getDepositShare)(reserve, new bignumber_js_1.default(reserve.depositsPoolRewardManager.totalShares.toString()))
|
|
@@ -55,29 +54,30 @@ const formatRewards = (parsedReserveMap, coinMetadataMap, priceMap, obligations)
|
|
|
55
54
|
perDay,
|
|
56
55
|
side,
|
|
57
56
|
},
|
|
58
|
-
obligationClaims: Object.fromEntries((
|
|
59
|
-
|
|
57
|
+
obligationClaims: Object.fromEntries((obligations !== null && obligations !== void 0 ? obligations : [])
|
|
58
|
+
.map((obligation) => {
|
|
59
|
+
const claim = getObligationClaim(obligation, poolReward, side === types_1.Side.DEPOSIT
|
|
60
60
|
? reserve.depositsPoolRewardManager.id
|
|
61
61
|
: reserve.borrowsPoolRewardManager.id, reserve.arrayIndex);
|
|
62
|
-
if (!claim)
|
|
62
|
+
if (!claim)
|
|
63
63
|
return undefined;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
return [obligation.id, claim];
|
|
65
|
+
})
|
|
66
|
+
.filter(Boolean)),
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
69
|
Object.values(parsedReserveMap).forEach((reserve) => {
|
|
70
70
|
const depositRewards = reserve.depositsPoolRewardManager.poolRewards.map((poolReward) => getRewardSummary(reserve, poolReward, types_1.Side.DEPOSIT));
|
|
71
71
|
const borrowRewards = reserve.borrowsPoolRewardManager.poolRewards.map((poolReward) => getRewardSummary(reserve, poolReward, types_1.Side.BORROW));
|
|
72
72
|
rewardMap[reserve.coinType] = {
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
[types_1.Side.DEPOSIT]: depositRewards,
|
|
74
|
+
[types_1.Side.BORROW]: borrowRewards,
|
|
75
75
|
};
|
|
76
76
|
});
|
|
77
77
|
return rewardMap;
|
|
78
78
|
};
|
|
79
79
|
exports.formatRewards = formatRewards;
|
|
80
|
-
const
|
|
80
|
+
const getObligationClaim = (obligation, poolReward, reservePoolManagerId, reserveArrayIndex) => {
|
|
81
81
|
const userRewardManager = obligation.original.userRewardManagers.find((urm) => urm.poolRewardManagerId === reservePoolManagerId);
|
|
82
82
|
if (!userRewardManager)
|
|
83
83
|
return;
|
|
@@ -85,8 +85,6 @@ const getObligationClaims = (obligation, poolReward, reservePoolManagerId, reser
|
|
|
85
85
|
if (!userReward)
|
|
86
86
|
return;
|
|
87
87
|
return {
|
|
88
|
-
// TODO: earnedRewards is refreshed via simulate.ts to only show unclaimed rewards.
|
|
89
|
-
// Lifetime earned amount is not available right yet as a result.
|
|
90
88
|
claimableAmount: (userReward === null || userReward === void 0 ? void 0 : userReward.earnedRewards)
|
|
91
89
|
? new bignumber_js_1.default(userReward.earnedRewards.value.toString())
|
|
92
90
|
.div(constants_1.WAD)
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"1.1.
|
|
1
|
+
{"name":"@suilend/sdk","version":"1.1.39","private":false,"description":"A TypeScript SDK for interacting with the Suilend program","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./client":"./client.js","./api/events":"./api/events.js","./api":"./api/index.js","./lib/constants":"./lib/constants.js","./lib":"./lib/index.js","./lib/initialize":"./lib/initialize.js","./lib/liquidityMining":"./lib/liquidityMining.js","./lib/transactions":"./lib/transactions.js","./lib/types":"./lib/types.js","./parsers/apiReserveAssetDataEvent":"./parsers/apiReserveAssetDataEvent.js","./parsers":"./parsers/index.js","./parsers/lendingMarket":"./parsers/lendingMarket.js","./parsers/obligation":"./parsers/obligation.js","./parsers/rateLimiter":"./parsers/rateLimiter.js","./parsers/reserve":"./parsers/reserve.js","./utils/events":"./utils/events.js","./utils":"./utils/index.js","./utils/obligation":"./utils/obligation.js","./utils/simulate":"./utils/simulate.js","./_generated/_framework/reified":"./_generated/_framework/reified.js","./_generated/_framework/util":"./_generated/_framework/util.js","./_generated/_framework/vector":"./_generated/_framework/vector.js","./_generated/suilend":"./_generated/suilend/index.js","./_generated/suilend/cell/structs":"./_generated/suilend/cell/structs.js","./_generated/suilend/decimal/structs":"./_generated/suilend/decimal/structs.js","./_generated/suilend/lending-market/functions":"./_generated/suilend/lending-market/functions.js","./_generated/suilend/lending-market/structs":"./_generated/suilend/lending-market/structs.js","./_generated/suilend/lending-market-registry/functions":"./_generated/suilend/lending-market-registry/functions.js","./_generated/suilend/liquidity-mining/structs":"./_generated/suilend/liquidity-mining/structs.js","./_generated/suilend/obligation/structs":"./_generated/suilend/obligation/structs.js","./_generated/suilend/rate-limiter/functions":"./_generated/suilend/rate-limiter/functions.js","./_generated/suilend/rate-limiter/structs":"./_generated/suilend/rate-limiter/structs.js","./_generated/suilend/reserve/structs":"./_generated/suilend/reserve/structs.js","./_generated/suilend/reserve-config/functions":"./_generated/suilend/reserve-config/functions.js","./_generated/suilend/reserve-config/structs":"./_generated/suilend/reserve-config/structs.js","./_generated/_dependencies/source/0x1":"./_generated/_dependencies/source/0x1/index.js","./_generated/_dependencies/source/0x2":"./_generated/_dependencies/source/0x2/index.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js","./_generated/_dependencies/source/0x1/ascii/structs":"./_generated/_dependencies/source/0x1/ascii/structs.js","./_generated/_dependencies/source/0x1/option/structs":"./_generated/_dependencies/source/0x1/option/structs.js","./_generated/_dependencies/source/0x1/type-name/structs":"./_generated/_dependencies/source/0x1/type-name/structs.js","./_generated/_dependencies/source/0x2/bag/structs":"./_generated/_dependencies/source/0x2/bag/structs.js","./_generated/_dependencies/source/0x2/balance/structs":"./_generated/_dependencies/source/0x2/balance/structs.js","./_generated/_dependencies/source/0x2/object/structs":"./_generated/_dependencies/source/0x2/object/structs.js","./_generated/_dependencies/source/0x2/object-table/structs":"./_generated/_dependencies/source/0x2/object-table/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js","./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix \"./src/**/*.ts\"","prettier":"prettier --write \"./src/**/*\"","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ts-node ./release.ts && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/solendprotocol/suilend-public.git"},"bugs":{"url":"https://github.com/solendprotocol/suilend-public/issues"},"dependencies":{"@pythnetwork/pyth-sui-js":"^2.1.0","bignumber.js":"^9.1.2","p-limit":"3.1.0","uuid":"^11.0.3"},"devDependencies":{"ts-node":"^10.9.2"},"peerDependencies":{"@mysten/bcs":"1.2.1","@mysten/sui":"1.20.0","@suilend/frontend-sui":"^0.2.38"}}
|
|
@@ -3,8 +3,9 @@ import BigNumber from "bignumber.js";
|
|
|
3
3
|
import { LendingMarket } from "../_generated/suilend/lending-market/structs";
|
|
4
4
|
import { Reserve } from "../_generated/suilend/reserve/structs";
|
|
5
5
|
export type ParsedLendingMarket = ReturnType<typeof parseLendingMarket>;
|
|
6
|
-
export declare const parseLendingMarket: (lendingMarket: LendingMarket<string>, reserves: Reserve<string>[], coinMetadataMap: Record<string, CoinMetadata>,
|
|
6
|
+
export declare const parseLendingMarket: (lendingMarket: LendingMarket<string>, reserves: Reserve<string>[], coinMetadataMap: Record<string, CoinMetadata>, nowS: number) => {
|
|
7
7
|
id: string;
|
|
8
|
+
type: string;
|
|
8
9
|
version: bigint;
|
|
9
10
|
reserves: {
|
|
10
11
|
config: {
|
|
@@ -132,6 +133,8 @@ export declare const parseLendingMarket: (lendingMarket: LendingMarket<string>,
|
|
|
132
133
|
depositedAmountUsd: BigNumber;
|
|
133
134
|
borrowedAmountUsd: BigNumber;
|
|
134
135
|
tvlUsd: BigNumber;
|
|
136
|
+
name: string;
|
|
137
|
+
ownerCapId: string;
|
|
135
138
|
/**
|
|
136
139
|
* @deprecated since version 1.0.3. Use `depositedAmountUsd` instead.
|
|
137
140
|
*/
|
package/parsers/lendingMarket.js
CHANGED
|
@@ -5,14 +5,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseLendingMarket = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
const client_1 = require("../client");
|
|
8
9
|
const rateLimiter_1 = require("./rateLimiter");
|
|
9
10
|
const reserve_1 = require("./reserve");
|
|
10
|
-
const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap,
|
|
11
|
+
const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, nowS) => {
|
|
12
|
+
var _a, _b;
|
|
11
13
|
const id = lendingMarket.id;
|
|
14
|
+
const type = lendingMarket.$typeArgs[0];
|
|
12
15
|
const version = lendingMarket.version;
|
|
13
16
|
const parsedReserves = reserves.map((reserve) => (0, reserve_1.parseReserve)(reserve, coinMetadataMap));
|
|
14
17
|
const obligations = lendingMarket.obligations;
|
|
15
|
-
const parsedRateLimiter = (0, rateLimiter_1.parseRateLimiter)(lendingMarket.rateLimiter,
|
|
18
|
+
const parsedRateLimiter = (0, rateLimiter_1.parseRateLimiter)(lendingMarket.rateLimiter, nowS);
|
|
16
19
|
const feeReceiver = lendingMarket.feeReceiver;
|
|
17
20
|
const badDebtUsd = new bignumber_js_1.default(lendingMarket.badDebtUsd.value.toString());
|
|
18
21
|
const badDebtLimitUsd = new bignumber_js_1.default(lendingMarket.badDebtLimitUsd.value.toString());
|
|
@@ -25,8 +28,14 @@ const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, currentTim
|
|
|
25
28
|
borrowedAmountUsd = borrowedAmountUsd.plus(parsedReserve.borrowedAmountUsd);
|
|
26
29
|
tvlUsd = tvlUsd.plus(parsedReserve.availableAmountUsd);
|
|
27
30
|
});
|
|
31
|
+
const LENDING_MARKET = client_1.LENDING_MARKETS.find((lm) => lm.id === id);
|
|
32
|
+
if (!LENDING_MARKET)
|
|
33
|
+
console.error(`Missing LENDING_MARKETS definition for lending market with id: ${id}`);
|
|
34
|
+
const name = (_a = LENDING_MARKET === null || LENDING_MARKET === void 0 ? void 0 : LENDING_MARKET.name) !== null && _a !== void 0 ? _a : "Unknown";
|
|
35
|
+
const ownerCapId = (_b = LENDING_MARKET === null || LENDING_MARKET === void 0 ? void 0 : LENDING_MARKET.ownerCapId) !== null && _b !== void 0 ? _b : "Unknown";
|
|
28
36
|
return {
|
|
29
37
|
id,
|
|
38
|
+
type,
|
|
30
39
|
version,
|
|
31
40
|
reserves: parsedReserves,
|
|
32
41
|
obligations,
|
|
@@ -37,6 +46,8 @@ const parseLendingMarket = (lendingMarket, reserves, coinMetadataMap, currentTim
|
|
|
37
46
|
depositedAmountUsd,
|
|
38
47
|
borrowedAmountUsd,
|
|
39
48
|
tvlUsd,
|
|
49
|
+
name,
|
|
50
|
+
ownerCapId,
|
|
40
51
|
/**
|
|
41
52
|
* @deprecated since version 1.0.3. Use `depositedAmountUsd` instead.
|
|
42
53
|
*/
|
package/parsers/rateLimiter.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import BigNumber from "bignumber.js";
|
|
|
2
2
|
import { RateLimiter } from "../_generated/suilend/rate-limiter/structs";
|
|
3
3
|
export type ParsedRateLimiter = ReturnType<typeof parseRateLimiter>;
|
|
4
4
|
export type ParsedRateLimiterConfig = ReturnType<typeof parseRateLimiterConfig>;
|
|
5
|
-
export declare const parseRateLimiter: (rateLimiter: RateLimiter,
|
|
5
|
+
export declare const parseRateLimiter: (rateLimiter: RateLimiter, nowS: number) => {
|
|
6
6
|
config: {
|
|
7
7
|
windowDuration: bigint;
|
|
8
8
|
maxOutflow: bigint;
|
package/parsers/rateLimiter.js
CHANGED
|
@@ -6,7 +6,7 @@ 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
8
|
const constants_1 = require("../lib/constants");
|
|
9
|
-
const parseRateLimiter = (rateLimiter,
|
|
9
|
+
const parseRateLimiter = (rateLimiter, nowS) => {
|
|
10
10
|
const config = (0, exports.parseRateLimiterConfig)(rateLimiter);
|
|
11
11
|
const $typeName = rateLimiter.$typeName;
|
|
12
12
|
const prevQty = rateLimiter.prevQty.value;
|
|
@@ -14,7 +14,7 @@ const parseRateLimiter = (rateLimiter, currentTime) => {
|
|
|
14
14
|
const curQty = rateLimiter.curQty.value;
|
|
15
15
|
// Custom
|
|
16
16
|
const prevWeight = new bignumber_js_1.default(config.windowDuration.toString())
|
|
17
|
-
.minus((BigInt(
|
|
17
|
+
.minus((BigInt(nowS) - windowStart + BigInt(1)).toString())
|
|
18
18
|
.div(config.windowDuration.toString());
|
|
19
19
|
const currentOutflow = prevWeight
|
|
20
20
|
.times(new bignumber_js_1.default(prevQty.toString()))
|
package/utils/obligation.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SuiClient } from "@mysten/sui/client";
|
|
2
2
|
import { Obligation } from "../_generated/suilend/obligation/structs";
|
|
3
|
-
export declare function fetchAllObligationsForMarketWithHandler(client: SuiClient,
|
|
4
|
-
export declare function fetchAllObligationsForMarket(client: SuiClient,
|
|
3
|
+
export declare function fetchAllObligationsForMarketWithHandler(client: SuiClient, lendingMarketId: string, lendingMarketType: string, chunkHandler: (obligations: Obligation<string>[]) => Promise<void>): Promise<void>;
|
|
4
|
+
export declare function fetchAllObligationsForMarket(client: SuiClient, lendingMarketId: string, lendingMarketType: string): Promise<Obligation<string>[]>;
|
|
5
5
|
export type FormattedObligationHistory = NonLiquidationHistoryEvent | LiquidationHistoryEvent;
|
|
6
6
|
export type NonLiquidationHistoryEvent = {
|
|
7
7
|
reserveId: string;
|
package/utils/obligation.js
CHANGED
|
@@ -53,14 +53,13 @@ const p_limit_1 = __importDefault(require("p-limit"));
|
|
|
53
53
|
const reified_1 = require("../_generated/_framework/reified");
|
|
54
54
|
const suilend_1 = require("../_generated/suilend");
|
|
55
55
|
const structs_1 = require("../_generated/suilend/obligation/structs");
|
|
56
|
-
const client_1 = require("../client");
|
|
57
56
|
const parsed = __importStar(require("./events"));
|
|
58
|
-
function fetchAllObligationsForMarketWithHandler(client,
|
|
57
|
+
function fetchAllObligationsForMarketWithHandler(client, lendingMarketId, lendingMarketType, chunkHandler) {
|
|
59
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
59
|
var _a;
|
|
61
60
|
const limit = (0, p_limit_1.default)(30);
|
|
62
61
|
const rawLendingMarket = yield client.getObject({
|
|
63
|
-
id:
|
|
62
|
+
id: lendingMarketId,
|
|
64
63
|
options: {
|
|
65
64
|
showType: true,
|
|
66
65
|
showContent: true,
|
|
@@ -86,7 +85,7 @@ function fetchAllObligationsForMarketWithHandler(client, marketAddress, chunkHan
|
|
|
86
85
|
const obligationObjects = yield chunkedMultiGet(client, response.data.map((x) => x.objectId));
|
|
87
86
|
const obligations = [];
|
|
88
87
|
for (const rawObligation of obligationObjects) {
|
|
89
|
-
obligations.push(structs_1.Obligation.fromBcs((0, reified_1.phantom)(
|
|
88
|
+
obligations.push(structs_1.Obligation.fromBcs((0, reified_1.phantom)(lendingMarketType), (0, utils_1.fromBase64)(((_a = rawObligation.data) === null || _a === void 0 ? void 0 : _a.bcs).bcsBytes)));
|
|
90
89
|
}
|
|
91
90
|
yield chunkHandler(obligations);
|
|
92
91
|
})));
|
|
@@ -94,11 +93,11 @@ function fetchAllObligationsForMarketWithHandler(client, marketAddress, chunkHan
|
|
|
94
93
|
yield Promise.all(promises);
|
|
95
94
|
});
|
|
96
95
|
}
|
|
97
|
-
function fetchAllObligationsForMarket(client,
|
|
96
|
+
function fetchAllObligationsForMarket(client, lendingMarketId, lendingMarketType) {
|
|
98
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
98
|
var _a, _b;
|
|
100
99
|
const rawLendingMarket = yield client.getObject({
|
|
101
|
-
id:
|
|
100
|
+
id: lendingMarketId,
|
|
102
101
|
options: {
|
|
103
102
|
showType: true,
|
|
104
103
|
showContent: true,
|
|
@@ -124,7 +123,7 @@ function fetchAllObligationsForMarket(client, marketAddress) {
|
|
|
124
123
|
const obligationObjects = yield chunkedMultiGet(client, fields.map((x) => x.objectId));
|
|
125
124
|
const obligations = [];
|
|
126
125
|
for (const rawObligation of obligationObjects) {
|
|
127
|
-
obligations.push(structs_1.Obligation.fromBcs((0, reified_1.phantom)(
|
|
126
|
+
obligations.push(structs_1.Obligation.fromBcs((0, reified_1.phantom)(lendingMarketType), (0, utils_1.fromBase64)(((_b = rawObligation.data) === null || _b === void 0 ? void 0 : _b.bcs).bcsBytes)));
|
|
128
127
|
}
|
|
129
128
|
return obligations;
|
|
130
129
|
});
|
package/utils/simulate.d.ts
CHANGED
|
@@ -19,10 +19,10 @@ export declare const calculateBorrowAprPercent: (reserve: Reserve<string>) => Bi
|
|
|
19
19
|
*/
|
|
20
20
|
export declare const calculateSupplyApr: (reserve: Reserve<string>) => BigNumber;
|
|
21
21
|
export declare const calculateDepositAprPercent: (reserve: Reserve<string>) => BigNumber;
|
|
22
|
-
export declare const compoundReserveInterest: (reserve: Reserve<string>,
|
|
22
|
+
export declare const compoundReserveInterest: (reserve: Reserve<string>, nowS: number) => Reserve<string>;
|
|
23
23
|
export declare const updatePoolRewardsManager: (manager: PoolRewardManager, nowMs: number) => PoolRewardManager;
|
|
24
24
|
export declare const refreshReservePrice: (reserves: Reserve<string>[], pythConnection: SuiPriceServiceConnection) => Promise<Reserve<string>[]>;
|
|
25
|
-
export declare const updateUserRewardManager: (poolManager: PoolRewardManager, userRewardManager: UserRewardManager,
|
|
25
|
+
export declare const updateUserRewardManager: (poolManager: PoolRewardManager, userRewardManager: UserRewardManager, nowMs: number) => UserRewardManager;
|
|
26
26
|
export declare const refreshObligation: (unrefreshedObligation: Obligation<string>, refreshedReserves: Reserve<string>[]) => Obligation<string>;
|
|
27
27
|
export declare const numberToDecimal: (value: number) => Decimal;
|
|
28
28
|
export declare const stringToDecimal: (value: string) => Decimal;
|
package/utils/simulate.js
CHANGED
|
@@ -79,9 +79,9 @@ const calculateDepositAprPercent = (reserve) => {
|
|
|
79
79
|
return (0, exports.calculateSupplyApr)(reserve);
|
|
80
80
|
};
|
|
81
81
|
exports.calculateDepositAprPercent = calculateDepositAprPercent;
|
|
82
|
-
const compoundReserveInterest = (reserve,
|
|
82
|
+
const compoundReserveInterest = (reserve, nowS) => {
|
|
83
83
|
var _a, _b;
|
|
84
|
-
const timeElapsedSeconds =
|
|
84
|
+
const timeElapsedSeconds = nowS - Number(reserve.interestLastUpdateTimestampS);
|
|
85
85
|
if (timeElapsedSeconds === 0) {
|
|
86
86
|
return reserve;
|
|
87
87
|
}
|
|
@@ -102,9 +102,9 @@ const compoundReserveInterest = (reserve, now) => {
|
|
|
102
102
|
.plus(netNewDebt.multipliedBy(spreadFee.dividedBy(10000)))
|
|
103
103
|
.toString());
|
|
104
104
|
updatedReserve.borrowedAmount = (0, exports.stringToDecimal)(oldBorrowedAmount.plus(netNewDebt).toString());
|
|
105
|
-
updatedReserve.interestLastUpdateTimestampS = BigInt(
|
|
106
|
-
updatedReserve.depositsPoolRewardManager = (0, exports.updatePoolRewardsManager)(updatedReserve.depositsPoolRewardManager,
|
|
107
|
-
updatedReserve.borrowsPoolRewardManager = (0, exports.updatePoolRewardsManager)(updatedReserve.borrowsPoolRewardManager,
|
|
105
|
+
updatedReserve.interestLastUpdateTimestampS = BigInt(nowS);
|
|
106
|
+
updatedReserve.depositsPoolRewardManager = (0, exports.updatePoolRewardsManager)(updatedReserve.depositsPoolRewardManager, nowS * 1000);
|
|
107
|
+
updatedReserve.borrowsPoolRewardManager = (0, exports.updatePoolRewardsManager)(updatedReserve.borrowsPoolRewardManager, nowS * 1000);
|
|
108
108
|
return updatedReserve;
|
|
109
109
|
};
|
|
110
110
|
exports.compoundReserveInterest = compoundReserveInterest;
|
|
@@ -161,7 +161,7 @@ const refreshReservePrice = (reserves, pythConnection) => __awaiter(void 0, void
|
|
|
161
161
|
return updatedReserves;
|
|
162
162
|
});
|
|
163
163
|
exports.refreshReservePrice = refreshReservePrice;
|
|
164
|
-
const updateUserRewardManager = (poolManager, userRewardManager,
|
|
164
|
+
const updateUserRewardManager = (poolManager, userRewardManager, nowMs) => {
|
|
165
165
|
const updatedUserRewardManager = Object.assign({}, userRewardManager);
|
|
166
166
|
for (let i = 0; i < poolManager.poolRewards.length; i++) {
|
|
167
167
|
const poolReward = poolManager.poolRewards[i];
|
|
@@ -193,7 +193,7 @@ const updateUserRewardManager = (poolManager, userRewardManager, now) => {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
updatedUserRewardManager.lastUpdateTimeMs = BigInt(
|
|
196
|
+
updatedUserRewardManager.lastUpdateTimeMs = BigInt(nowMs);
|
|
197
197
|
return updatedUserRewardManager;
|
|
198
198
|
};
|
|
199
199
|
exports.updateUserRewardManager = updateUserRewardManager;
|