@suilend/sdk 2.0.4 → 3.0.2
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/_dependencies/source/0x1/ascii/structs.d.ts +7 -11
- package/_generated/_dependencies/source/0x1/ascii/structs.js +6 -63
- package/_generated/_dependencies/source/0x1/option/structs.d.ts +3 -9
- package/_generated/_dependencies/source/0x1/option/structs.js +4 -42
- package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +5 -7
- package/_generated/_dependencies/source/0x1/type-name/structs.js +3 -32
- package/_generated/_dependencies/source/0x2/bag/structs.d.ts +7 -9
- package/_generated/_dependencies/source/0x2/bag/structs.js +3 -31
- package/_generated/_dependencies/source/0x2/balance/structs.d.ts +7 -11
- package/_generated/_dependencies/source/0x2/balance/structs.js +7 -82
- package/_generated/_dependencies/source/0x2/object/structs.d.ts +8 -12
- package/_generated/_dependencies/source/0x2/object/structs.js +7 -61
- package/_generated/_dependencies/source/0x2/object-table/structs.d.ts +7 -9
- package/_generated/_dependencies/source/0x2/object-table/structs.js +4 -44
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.d.ts +5 -7
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js +3 -31
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.d.ts +11 -13
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js +3 -32
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.d.ts +23 -25
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js +3 -32
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +4 -6
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +3 -33
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.d.ts +55 -59
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js +6 -64
- package/_generated/_framework/reified.d.ts +2 -4
- package/_generated/_framework/vector.d.ts +2 -12
- package/_generated/suilend/cell/structs.d.ts +4 -10
- package/_generated/suilend/cell/structs.js +4 -42
- package/_generated/suilend/decimal/structs.d.ts +4 -6
- package/_generated/suilend/decimal/structs.js +3 -32
- package/_generated/suilend/lending-market/structs.d.ts +152 -392
- package/_generated/suilend/lending-market/structs.js +50 -548
- package/_generated/suilend/liquidity-mining/structs.d.ts +50 -158
- package/_generated/suilend/liquidity-mining/structs.js +16 -169
- package/_generated/suilend/obligation/structs.d.ts +108 -148
- package/_generated/suilend/obligation/structs.js +23 -232
- package/_generated/suilend/rate-limiter/structs.d.ts +15 -19
- package/_generated/suilend/rate-limiter/structs.js +6 -64
- package/_generated/suilend/reserve/structs.d.ts +138 -362
- package/_generated/suilend/reserve/structs.js +29 -327
- package/_generated/suilend/reserve-config/structs.d.ts +33 -37
- package/_generated/suilend/reserve-config/structs.js +6 -65
- package/client.d.ts +8 -8
- package/client.js +55 -88
- package/lib/initialize.d.ts +29 -28
- package/lib/initialize.js +20 -16
- package/lib/liquidityMining.d.ts +3 -3
- package/lib/pythAdapter.d.ts +9 -0
- package/lib/pythAdapter.js +120 -0
- package/lib/strategyOwnerCap.d.ts +12 -7
- package/lib/strategyOwnerCap.js +159 -156
- package/margin/margin/admin_cap.d.ts +2 -2
- package/margin/margin/deps/std/type_name.d.ts +1 -1
- package/margin/margin/deps/sui/vec_set.d.ts +3 -5
- package/margin/margin/deps/suilend/lending_market.d.ts +2 -2
- package/margin/margin/market.d.ts +21 -38
- package/margin/margin/position.d.ts +47 -47
- package/margin/margin/router.d.ts +5 -5
- package/margin/margin/version.d.ts +1 -1
- package/package.json +1 -1
- package/parsers/lendingMarket.d.ts +6 -6
- package/parsers/obligation.d.ts +8 -8
- package/parsers/reserve.d.ts +8 -8
- package/strategies.d.ts +38 -21
- package/strategies.js +239 -79
- package/swap/quote.d.ts +1 -9
- package/swap/quote.js +1 -52
- package/swap/transaction.d.ts +2 -4
- package/swap/transaction.js +9 -25
- package/utils/events.d.ts +6 -5
- package/utils/events.js +11 -8
- package/utils/obligation.d.ts +6 -5
- package/utils/obligation.js +118 -117
|
@@ -13,7 +13,6 @@ import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, field
|
|
|
13
13
|
import { composeSuiType, compressSuiType, } from "../../_framework/util";
|
|
14
14
|
import { PKG_V1 } from "../index";
|
|
15
15
|
import { bcs } from "@mysten/sui/bcs";
|
|
16
|
-
import { fromBase64 } from "@mysten/sui/utils";
|
|
17
16
|
/* ============================== ReserveConfig =============================== */
|
|
18
17
|
export function isReserveConfig(type) {
|
|
19
18
|
type = compressSuiType(type);
|
|
@@ -59,8 +58,6 @@ export class ReserveConfig {
|
|
|
59
58
|
bcs: ReserveConfig.bcs,
|
|
60
59
|
fromJSONField: (field) => ReserveConfig.fromJSONField(field),
|
|
61
60
|
fromJSON: (json) => ReserveConfig.fromJSON(json),
|
|
62
|
-
fromSuiParsedData: (content) => ReserveConfig.fromSuiParsedData(content),
|
|
63
|
-
fromSuiObjectData: (content) => ReserveConfig.fromSuiObjectData(content),
|
|
64
61
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return ReserveConfig.fetch(client, id); }),
|
|
65
62
|
new: (fields) => {
|
|
66
63
|
return new ReserveConfig([], fields);
|
|
@@ -207,40 +204,13 @@ export class ReserveConfig {
|
|
|
207
204
|
}
|
|
208
205
|
return ReserveConfig.fromJSONField(json);
|
|
209
206
|
}
|
|
210
|
-
static fromSuiParsedData(content) {
|
|
211
|
-
if (content.dataType !== "moveObject") {
|
|
212
|
-
throw new Error("not an object");
|
|
213
|
-
}
|
|
214
|
-
if (!isReserveConfig(content.type)) {
|
|
215
|
-
throw new Error(`object at ${content.fields.id} is not a ReserveConfig object`);
|
|
216
|
-
}
|
|
217
|
-
return ReserveConfig.fromFieldsWithTypes(content);
|
|
218
|
-
}
|
|
219
|
-
static fromSuiObjectData(data) {
|
|
220
|
-
if (data.bcs) {
|
|
221
|
-
if (data.bcs.dataType !== "moveObject" ||
|
|
222
|
-
!isReserveConfig(data.bcs.type)) {
|
|
223
|
-
throw new Error(`object at is not a ReserveConfig object`);
|
|
224
|
-
}
|
|
225
|
-
return ReserveConfig.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
226
|
-
}
|
|
227
|
-
if (data.content) {
|
|
228
|
-
return ReserveConfig.fromSuiParsedData(data.content);
|
|
229
|
-
}
|
|
230
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
231
|
-
}
|
|
232
207
|
static fetch(client, id) {
|
|
233
208
|
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (res.error) {
|
|
237
|
-
throw new Error(`error fetching ReserveConfig object at id ${id}: ${res.error.code}`);
|
|
238
|
-
}
|
|
239
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
240
|
-
!isReserveConfig(res.data.bcs.type)) {
|
|
209
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
210
|
+
if (!isReserveConfig(object.type)) {
|
|
241
211
|
throw new Error(`object at id ${id} is not a ReserveConfig object`);
|
|
242
212
|
}
|
|
243
|
-
return ReserveConfig.
|
|
213
|
+
return ReserveConfig.fromBcs(object.content);
|
|
244
214
|
});
|
|
245
215
|
}
|
|
246
216
|
}
|
|
@@ -274,8 +244,6 @@ export class ReserveConfigBuilder {
|
|
|
274
244
|
bcs: ReserveConfigBuilder.bcs,
|
|
275
245
|
fromJSONField: (field) => ReserveConfigBuilder.fromJSONField(field),
|
|
276
246
|
fromJSON: (json) => ReserveConfigBuilder.fromJSON(json),
|
|
277
|
-
fromSuiParsedData: (content) => ReserveConfigBuilder.fromSuiParsedData(content),
|
|
278
|
-
fromSuiObjectData: (content) => ReserveConfigBuilder.fromSuiObjectData(content),
|
|
279
247
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return ReserveConfigBuilder.fetch(client, id); }),
|
|
280
248
|
new: (fields) => {
|
|
281
249
|
return new ReserveConfigBuilder([], fields);
|
|
@@ -332,40 +300,13 @@ export class ReserveConfigBuilder {
|
|
|
332
300
|
}
|
|
333
301
|
return ReserveConfigBuilder.fromJSONField(json);
|
|
334
302
|
}
|
|
335
|
-
static fromSuiParsedData(content) {
|
|
336
|
-
if (content.dataType !== "moveObject") {
|
|
337
|
-
throw new Error("not an object");
|
|
338
|
-
}
|
|
339
|
-
if (!isReserveConfigBuilder(content.type)) {
|
|
340
|
-
throw new Error(`object at ${content.fields.id} is not a ReserveConfigBuilder object`);
|
|
341
|
-
}
|
|
342
|
-
return ReserveConfigBuilder.fromFieldsWithTypes(content);
|
|
343
|
-
}
|
|
344
|
-
static fromSuiObjectData(data) {
|
|
345
|
-
if (data.bcs) {
|
|
346
|
-
if (data.bcs.dataType !== "moveObject" ||
|
|
347
|
-
!isReserveConfigBuilder(data.bcs.type)) {
|
|
348
|
-
throw new Error(`object at is not a ReserveConfigBuilder object`);
|
|
349
|
-
}
|
|
350
|
-
return ReserveConfigBuilder.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
351
|
-
}
|
|
352
|
-
if (data.content) {
|
|
353
|
-
return ReserveConfigBuilder.fromSuiParsedData(data.content);
|
|
354
|
-
}
|
|
355
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
356
|
-
}
|
|
357
303
|
static fetch(client, id) {
|
|
358
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (res.error) {
|
|
362
|
-
throw new Error(`error fetching ReserveConfigBuilder object at id ${id}: ${res.error.code}`);
|
|
363
|
-
}
|
|
364
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
365
|
-
!isReserveConfigBuilder(res.data.bcs.type)) {
|
|
305
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
306
|
+
if (!isReserveConfigBuilder(object.type)) {
|
|
366
307
|
throw new Error(`object at id ${id} is not a ReserveConfigBuilder object`);
|
|
367
308
|
}
|
|
368
|
-
return ReserveConfigBuilder.
|
|
309
|
+
return ReserveConfigBuilder.fromBcs(object.content);
|
|
369
310
|
});
|
|
370
311
|
}
|
|
371
312
|
}
|
package/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
2
2
|
import { Transaction, TransactionObjectArgument, TransactionObjectInput } from "@mysten/sui/transactions";
|
|
3
3
|
import { SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js";
|
|
4
4
|
import { LendingMarket, ObligationOwnerCap } from "./_generated/suilend/lending-market/structs";
|
|
@@ -29,12 +29,12 @@ export type ClaimRewardsReward = {
|
|
|
29
29
|
};
|
|
30
30
|
export declare class SuilendClient {
|
|
31
31
|
lendingMarket: LendingMarket<string>;
|
|
32
|
-
|
|
32
|
+
suiGrpcClient: SuiGrpcClient;
|
|
33
33
|
pythClient: SuiPythClient;
|
|
34
34
|
pythConnection: SuiPriceServiceConnection;
|
|
35
|
-
constructor(lendingMarket: LendingMarket<string>,
|
|
36
|
-
static initialize(lendingMarketId: string, lendingMarketType: string,
|
|
37
|
-
static getFeeReceivers(
|
|
35
|
+
constructor(lendingMarket: LendingMarket<string>, suiGrpcClient: SuiGrpcClient);
|
|
36
|
+
static initialize(lendingMarketId: string, lendingMarketType: string, suiGrpcClient: SuiGrpcClient, logPackageId?: boolean): Promise<SuilendClient>;
|
|
37
|
+
static getFeeReceivers(suiGrpcClient: SuiGrpcClient, lendingMarketId: string): Promise<{
|
|
38
38
|
receivers: string[];
|
|
39
39
|
weights: string[];
|
|
40
40
|
}>;
|
|
@@ -42,10 +42,10 @@ export declare class SuilendClient {
|
|
|
42
42
|
NestedResult: [number, number];
|
|
43
43
|
$kind: "NestedResult";
|
|
44
44
|
};
|
|
45
|
-
static getObligationOwnerCaps(ownerId: string, lendingMarketTypeArgs: string[],
|
|
46
|
-
static getObligation(obligationId: string, lendingMarketTypeArgs: string[],
|
|
45
|
+
static getObligationOwnerCaps(ownerId: string, lendingMarketTypeArgs: string[], suiGrpcClient: SuiGrpcClient): Promise<ObligationOwnerCap<string>[]>;
|
|
46
|
+
static getObligation(obligationId: string, lendingMarketTypeArgs: string[], suiGrpcClient: SuiGrpcClient): Promise<Obligation<string>>;
|
|
47
47
|
getObligation(obligationId: string): Promise<Obligation<string>>;
|
|
48
|
-
static getLendingMarketOwnerCapId(ownerId: string, lendingMarketTypeArgs: string[],
|
|
48
|
+
static getLendingMarketOwnerCapId(ownerId: string, lendingMarketTypeArgs: string[], suiGrpcClient: SuiGrpcClient): Promise<string | undefined>;
|
|
49
49
|
getLendingMarketOwnerCapId(ownerId: string): Promise<string | undefined>;
|
|
50
50
|
createReserve(lendingMarketOwnerCapId: string, transaction: Transaction, pythPriceId: string, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs, useV2?: boolean): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
|
51
51
|
addReward(ownerId: string, lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardCoinType: string, rewardValue: string, startTimeMs: bigint, endTimeMs: bigint, transaction: Transaction, mergeCoins?: boolean): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
package/client.js
CHANGED
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID,
|
|
10
|
+
import { SUI_CLOCK_OBJECT_ID, SUI_SYSTEM_STATE_OBJECT_ID, normalizeStructTag, toHex, } from "@mysten/sui/utils";
|
|
11
11
|
import { SuiPriceServiceConnection, SuiPythClient, } from "@pythnetwork/pyth-sui-js";
|
|
12
12
|
import { extractCTokenCoinType, getAllCoins, mergeAllCoins, } from "@suilend/sui-fe";
|
|
13
13
|
import { PriceInfoObject } from "./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs";
|
|
@@ -21,6 +21,7 @@ import { Obligation } from "./_generated/suilend/obligation/structs";
|
|
|
21
21
|
import { newConfig as createRateLimiterConfig, } from "./_generated/suilend/rate-limiter/functions";
|
|
22
22
|
import { createReserveConfig, } from "./_generated/suilend/reserve-config/functions";
|
|
23
23
|
import { PRIMARY_PYTH_ENDPOINT } from "./lib/pyth";
|
|
24
|
+
import { createJsonRpcAdapter } from "./lib/pythAdapter";
|
|
24
25
|
import { Side } from "./lib/types";
|
|
25
26
|
const SUI_COINTYPE = "0x2::sui::SUI";
|
|
26
27
|
const NORMALIZED_SUI_COINTYPE = normalizeStructTag(SUI_COINTYPE);
|
|
@@ -54,54 +55,48 @@ export const [STEAMM_LM_LENDING_MARKET_ID, STEAMM_LM_LENDING_MARKET_TYPE] = proc
|
|
|
54
55
|
"0xc1888ec1b81a414e427a44829310508352aec38252ee0daa9f8b181b6947de9f",
|
|
55
56
|
"0x0a071f4976abae1a7f722199cf0bfcbe695ef9408a878e7d12a7ca87b7e582a6::lp_rewards::LP_REWARDS",
|
|
56
57
|
];
|
|
57
|
-
function getLatestPackageId(
|
|
58
|
+
function getLatestPackageId(suiGrpcClient, upgradeCapId) {
|
|
58
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
return ((_a = object.data) === null || _a === void 0 ? void 0 : _a.content).fields.package;
|
|
60
|
+
const { object } = yield suiGrpcClient.getObject({
|
|
61
|
+
objectId: upgradeCapId,
|
|
62
|
+
include: { json: true },
|
|
63
|
+
});
|
|
64
|
+
return object.json.package;
|
|
67
65
|
});
|
|
68
66
|
}
|
|
69
67
|
export class SuilendClient {
|
|
70
|
-
constructor(lendingMarket,
|
|
68
|
+
constructor(lendingMarket, suiGrpcClient) {
|
|
71
69
|
this.lendingMarket = lendingMarket;
|
|
72
|
-
this.
|
|
73
|
-
this.pythClient = new SuiPythClient(
|
|
70
|
+
this.suiGrpcClient = suiGrpcClient;
|
|
71
|
+
this.pythClient = new SuiPythClient(createJsonRpcAdapter(suiGrpcClient), PYTH_STATE_ID, WORMHOLE_STATE_ID);
|
|
74
72
|
const pythEndpoint = PRIMARY_PYTH_ENDPOINT; // TODO: Use getWorkingPythEndpoint
|
|
75
73
|
this.pythConnection = new SuiPriceServiceConnection(pythEndpoint, {
|
|
76
74
|
timeout: 30 * 1000,
|
|
77
75
|
});
|
|
78
76
|
}
|
|
79
|
-
static initialize(lendingMarketId, lendingMarketType,
|
|
77
|
+
static initialize(lendingMarketId, lendingMarketType, suiGrpcClient, logPackageId) {
|
|
80
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
const lendingMarket = yield LendingMarket.fetch(
|
|
82
|
-
const publishedAt = yield getLatestPackageId(
|
|
79
|
+
const lendingMarket = yield LendingMarket.fetch(suiGrpcClient, phantom(lendingMarketType), lendingMarketId);
|
|
80
|
+
const publishedAt = yield getLatestPackageId(suiGrpcClient, SUILEND_UPGRADE_CAP_ID);
|
|
83
81
|
if (logPackageId)
|
|
84
82
|
console.log("@suilend/sdk | publishedAt:", publishedAt);
|
|
85
83
|
setPublishedAt(publishedAt);
|
|
86
|
-
return new SuilendClient(lendingMarket,
|
|
84
|
+
return new SuilendClient(lendingMarket, suiGrpcClient);
|
|
87
85
|
});
|
|
88
86
|
}
|
|
89
|
-
static getFeeReceivers(
|
|
87
|
+
static getFeeReceivers(suiGrpcClient, lendingMarketId) {
|
|
90
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
var _a, _b;
|
|
92
|
-
const
|
|
89
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
90
|
+
const { dynamicField } = yield suiGrpcClient.getDynamicField({
|
|
93
91
|
parentId: lendingMarketId,
|
|
94
92
|
name: {
|
|
95
93
|
type: `${PKG_V10}::lending_market::FeeReceiversKey`,
|
|
96
|
-
|
|
97
|
-
dummy_field: false,
|
|
98
|
-
},
|
|
94
|
+
bcs: new Uint8Array([0]),
|
|
99
95
|
},
|
|
100
96
|
});
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
const weights = ((
|
|
104
|
-
.weights;
|
|
97
|
+
const value = dynamicField.value;
|
|
98
|
+
const receivers = (_d = (_c = (_b = (_a = value.json) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.fields) === null || _d === void 0 ? void 0 : _d.receivers;
|
|
99
|
+
const weights = (_h = (_g = (_f = (_e = value.json) === null || _e === void 0 ? void 0 : _e.fields) === null || _f === void 0 ? void 0 : _f.value) === null || _g === void 0 ? void 0 : _g.fields) === null || _h === void 0 ? void 0 : _h.weights;
|
|
105
100
|
return { receivers, weights };
|
|
106
101
|
});
|
|
107
102
|
}
|
|
@@ -114,82 +109,54 @@ export class SuilendClient {
|
|
|
114
109
|
});
|
|
115
110
|
return ownerCap;
|
|
116
111
|
}
|
|
117
|
-
static getObligationOwnerCaps(ownerId, lendingMarketTypeArgs,
|
|
112
|
+
static getObligationOwnerCaps(ownerId, lendingMarketTypeArgs, suiGrpcClient) {
|
|
118
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
119
114
|
const allObjs = [];
|
|
120
115
|
let cursor = null;
|
|
121
116
|
let hasNextPage = true;
|
|
122
117
|
while (hasNextPage) {
|
|
123
|
-
const objs = yield
|
|
118
|
+
const objs = yield suiGrpcClient.listOwnedObjects({
|
|
124
119
|
owner: ownerId,
|
|
125
120
|
cursor,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
},
|
|
121
|
+
type: `${PACKAGE_ID}::lending_market::ObligationOwnerCap<${lendingMarketTypeArgs[0]}>`,
|
|
122
|
+
include: { content: true },
|
|
129
123
|
});
|
|
130
|
-
allObjs.push(...objs.
|
|
131
|
-
cursor = objs.
|
|
124
|
+
allObjs.push(...objs.objects);
|
|
125
|
+
cursor = objs.cursor;
|
|
132
126
|
hasNextPage = objs.hasNextPage;
|
|
133
127
|
}
|
|
134
|
-
|
|
135
|
-
const obligationOwnerCapObjs = yield Promise.all(allObjs.map((objData) => {
|
|
136
|
-
var _a;
|
|
137
|
-
return client.getObject({
|
|
138
|
-
id: (_a = objData.data) === null || _a === void 0 ? void 0 : _a.objectId,
|
|
139
|
-
options: { showBcs: true },
|
|
140
|
-
});
|
|
141
|
-
}));
|
|
142
|
-
const obligationOwnerCaps = [];
|
|
143
|
-
obligationOwnerCapObjs.forEach((obj) => {
|
|
144
|
-
var _a, _b, _c, _d;
|
|
145
|
-
if (((_b = (_a = obj.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject")
|
|
146
|
-
throw new Error("Error: invalid data type");
|
|
147
|
-
obligationOwnerCaps.push(ObligationOwnerCap.fromBcs(phantom(lendingMarketTypeArgs[0]), fromBase64((_d = (_c = obj.data) === null || _c === void 0 ? void 0 : _c.bcs) === null || _d === void 0 ? void 0 : _d.bcsBytes)));
|
|
148
|
-
});
|
|
149
|
-
return obligationOwnerCaps;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
return [];
|
|
153
|
-
}
|
|
128
|
+
return allObjs.map((obj) => ObligationOwnerCap.fromBcs(phantom(lendingMarketTypeArgs[0]), obj.content));
|
|
154
129
|
});
|
|
155
130
|
}
|
|
156
|
-
static getObligation(obligationId, lendingMarketTypeArgs,
|
|
131
|
+
static getObligation(obligationId, lendingMarketTypeArgs, suiGrpcClient) {
|
|
157
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
options: { showBcs: true },
|
|
133
|
+
const { object } = yield suiGrpcClient.getObject({
|
|
134
|
+
objectId: obligationId,
|
|
135
|
+
include: { content: true },
|
|
162
136
|
});
|
|
163
|
-
|
|
164
|
-
throw new Error("Error: invalid data type");
|
|
165
|
-
}
|
|
166
|
-
const obligation = Obligation.fromBcs(phantom(lendingMarketTypeArgs[0]), fromBase64(obligationData.data.bcs.bcsBytes));
|
|
167
|
-
return obligation;
|
|
137
|
+
return Obligation.fromBcs(phantom(lendingMarketTypeArgs[0]), object.content);
|
|
168
138
|
});
|
|
169
139
|
}
|
|
170
140
|
getObligation(obligationId) {
|
|
171
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
return SuilendClient.getObligation(obligationId, this.lendingMarket.$typeArgs, this.
|
|
142
|
+
return SuilendClient.getObligation(obligationId, this.lendingMarket.$typeArgs, this.suiGrpcClient);
|
|
173
143
|
});
|
|
174
144
|
}
|
|
175
|
-
static getLendingMarketOwnerCapId(ownerId, lendingMarketTypeArgs,
|
|
145
|
+
static getLendingMarketOwnerCapId(ownerId, lendingMarketTypeArgs, suiGrpcClient) {
|
|
176
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
|
|
178
|
-
const objs = yield client.getOwnedObjects({
|
|
147
|
+
const objs = yield suiGrpcClient.listOwnedObjects({
|
|
179
148
|
owner: ownerId,
|
|
180
|
-
|
|
181
|
-
StructType: `${PACKAGE_ID}::lending_market::LendingMarketOwnerCap<${lendingMarketTypeArgs[0]}>`,
|
|
182
|
-
},
|
|
149
|
+
type: `${PACKAGE_ID}::lending_market::LendingMarketOwnerCap<${lendingMarketTypeArgs[0]}>`,
|
|
183
150
|
});
|
|
184
|
-
if (objs.
|
|
185
|
-
return
|
|
151
|
+
if (objs.objects.length > 0)
|
|
152
|
+
return objs.objects[0].objectId;
|
|
186
153
|
else
|
|
187
154
|
return undefined;
|
|
188
155
|
});
|
|
189
156
|
}
|
|
190
157
|
getLendingMarketOwnerCapId(ownerId) {
|
|
191
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
return SuilendClient.getLendingMarketOwnerCapId(ownerId, this.lendingMarket.$typeArgs, this.
|
|
159
|
+
return SuilendClient.getLendingMarketOwnerCapId(ownerId, this.lendingMarket.$typeArgs, this.suiGrpcClient);
|
|
193
160
|
});
|
|
194
161
|
}
|
|
195
162
|
createReserve(lendingMarketOwnerCapId, transaction, pythPriceId, coinType, createReserveConfigArgs, useV2) {
|
|
@@ -200,7 +167,7 @@ export class SuilendClient {
|
|
|
200
167
|
pythPriceId,
|
|
201
168
|
]);
|
|
202
169
|
const priceInfoObjectIds = yield this.pythClient.updatePriceFeeds(transaction, priceUpdateData, [pythPriceId]);
|
|
203
|
-
const coinMetadata = yield this.
|
|
170
|
+
const { coinMetadata } = yield this.suiGrpcClient.getCoinMetadata({
|
|
204
171
|
coinType: coinType,
|
|
205
172
|
});
|
|
206
173
|
console.log("[createReserve] coinMetadata", coinMetadata);
|
|
@@ -221,16 +188,16 @@ export class SuilendClient {
|
|
|
221
188
|
}
|
|
222
189
|
addReward(ownerId_1, lendingMarketOwnerCapId_1, reserveArrayIndex_1, isDepositReward_1, rewardCoinType_1, rewardValue_1, startTimeMs_1, endTimeMs_1, transaction_1) {
|
|
223
190
|
return __awaiter(this, arguments, void 0, function* (ownerId, lendingMarketOwnerCapId, reserveArrayIndex, isDepositReward, rewardCoinType, rewardValue, startTimeMs, endTimeMs, transaction, mergeCoins = true) {
|
|
224
|
-
const coins = (yield this.
|
|
191
|
+
const coins = (yield this.suiGrpcClient.listCoins({
|
|
225
192
|
owner: ownerId,
|
|
226
193
|
coinType: rewardCoinType,
|
|
227
|
-
})).
|
|
194
|
+
})).objects;
|
|
228
195
|
if (coins.length > 1 && !isSui(rewardCoinType) && mergeCoins) {
|
|
229
|
-
transaction.mergeCoins(transaction.object(coins[0].
|
|
196
|
+
transaction.mergeCoins(transaction.object(coins[0].objectId), coins.map((c) => transaction.object(c.objectId)).slice(1));
|
|
230
197
|
}
|
|
231
198
|
const [rewardCoin] = transaction.splitCoins(isSui(rewardCoinType)
|
|
232
199
|
? transaction.gas
|
|
233
|
-
: transaction.object(coins[0].
|
|
200
|
+
: transaction.object(coins[0].objectId), [rewardValue]);
|
|
234
201
|
return addPoolReward(transaction, [this.lendingMarket.$typeArgs[0], rewardCoinType], {
|
|
235
202
|
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
236
203
|
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
@@ -400,7 +367,7 @@ export class SuilendClient {
|
|
|
400
367
|
}))()));
|
|
401
368
|
const stalePriceIdentifiers = [];
|
|
402
369
|
yield Promise.all(Object.entries(priceInfoObjectIds).map(([i, priceInfoObjectId]) => (() => __awaiter(this, void 0, void 0, function* () {
|
|
403
|
-
const priceInfoObject = yield PriceInfoObject.fetch(this.
|
|
370
|
+
const priceInfoObject = yield PriceInfoObject.fetch(this.suiGrpcClient, priceInfoObjectId);
|
|
404
371
|
const publishTime = priceInfoObject.priceInfo.priceFeed.price.timestamp;
|
|
405
372
|
const stalenessSeconds = Date.now() / 1000 - Number(publishTime);
|
|
406
373
|
if (stalenessSeconds > 20) {
|
|
@@ -454,21 +421,21 @@ export class SuilendClient {
|
|
|
454
421
|
}
|
|
455
422
|
depositIntoObligation(ownerId, coinType, value, transaction, obligationOwnerCap) {
|
|
456
423
|
return __awaiter(this, void 0, void 0, function* () {
|
|
457
|
-
const coins = yield getAllCoins(this.
|
|
424
|
+
const coins = yield getAllCoins(this.suiGrpcClient, ownerId, coinType);
|
|
458
425
|
const mergeCoin = mergeAllCoins(coinType, transaction, coins);
|
|
459
426
|
const [sendCoin] = transaction.splitCoins(isSui(coinType)
|
|
460
427
|
? transaction.gas
|
|
461
|
-
: transaction.object(mergeCoin.
|
|
428
|
+
: transaction.object(mergeCoin.objectId), [value]);
|
|
462
429
|
this.deposit(sendCoin, coinType, obligationOwnerCap, transaction);
|
|
463
430
|
});
|
|
464
431
|
}
|
|
465
432
|
depositLiquidityAndGetCTokens(ownerId, coinType, value, transaction) {
|
|
466
433
|
return __awaiter(this, void 0, void 0, function* () {
|
|
467
|
-
const coins = yield getAllCoins(this.
|
|
434
|
+
const coins = yield getAllCoins(this.suiGrpcClient, ownerId, coinType);
|
|
468
435
|
const mergeCoin = mergeAllCoins(coinType, transaction, coins);
|
|
469
436
|
const [sendCoin] = transaction.splitCoins(isSui(coinType)
|
|
470
437
|
? transaction.gas
|
|
471
|
-
: transaction.object(mergeCoin.
|
|
438
|
+
: transaction.object(mergeCoin.objectId), [value]);
|
|
472
439
|
const [ctokens] = depositLiquidityAndMintCtokens(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
473
440
|
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
474
441
|
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
@@ -578,11 +545,11 @@ export class SuilendClient {
|
|
|
578
545
|
}
|
|
579
546
|
repayIntoObligation(ownerId, obligationId, coinType, value, transaction) {
|
|
580
547
|
return __awaiter(this, void 0, void 0, function* () {
|
|
581
|
-
const coins = yield getAllCoins(this.
|
|
548
|
+
const coins = yield getAllCoins(this.suiGrpcClient, ownerId, coinType);
|
|
582
549
|
const mergeCoin = mergeAllCoins(coinType, transaction, coins);
|
|
583
550
|
const [sendCoin] = transaction.splitCoins(isSui(coinType)
|
|
584
551
|
? transaction.gas
|
|
585
|
-
: transaction.object(mergeCoin.
|
|
552
|
+
: transaction.object(mergeCoin.objectId), [value]);
|
|
586
553
|
const result = this.repay(obligationId, coinType, sendCoin, transaction);
|
|
587
554
|
transaction.transferObjects([sendCoin], transaction.pure.address(ownerId));
|
|
588
555
|
return result;
|
|
@@ -639,7 +606,7 @@ export class SuilendClient {
|
|
|
639
606
|
return __awaiter(this, void 0, void 0, function* () {
|
|
640
607
|
const mergeCoinMap = {};
|
|
641
608
|
for (const ctokenCoinType of ctokenCoinTypes) {
|
|
642
|
-
const coins = yield getAllCoins(this.
|
|
609
|
+
const coins = yield getAllCoins(this.suiGrpcClient, ownerId, ctokenCoinType);
|
|
643
610
|
const mergeCoin = mergeAllCoins(ctokenCoinType, transaction, coins);
|
|
644
611
|
mergeCoinMap[ctokenCoinType] = mergeCoin;
|
|
645
612
|
}
|
|
@@ -652,7 +619,7 @@ export class SuilendClient {
|
|
|
652
619
|
],
|
|
653
620
|
arguments: [],
|
|
654
621
|
});
|
|
655
|
-
const [redeemCoin] = this.redeem(transaction.object(mergeCoin.
|
|
622
|
+
const [redeemCoin] = this.redeem(transaction.object(mergeCoin.objectId), coinType, exemption, transaction);
|
|
656
623
|
transaction.transferObjects([redeemCoin], transaction.pure.address(ownerId));
|
|
657
624
|
}
|
|
658
625
|
});
|
package/lib/initialize.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SuiClientTypes } from "@mysten/sui/client";
|
|
2
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
2
3
|
import BigNumber from "bignumber.js";
|
|
3
4
|
import { Reserve } from "../_generated/suilend/reserve/structs";
|
|
4
5
|
import { SuilendClient } from "../client";
|
|
@@ -8,7 +9,7 @@ export declare const RESERVES_CUSTOM_ORDER: Record<string, string[]>;
|
|
|
8
9
|
export declare const NORMALIZED_MAYA_COINTYPE: string;
|
|
9
10
|
export declare const NORMALIZED_mPOINTS_COINTYPE: string;
|
|
10
11
|
export declare const NORMALIZED_TREATS_COINTYPE: string;
|
|
11
|
-
export declare const initializeSuilend: (
|
|
12
|
+
export declare const initializeSuilend: (suiGrpcClient: SuiGrpcClient, suilendClient: SuilendClient, lendingMarketMetadata?: LendingMarketMetadata, fallbackPythEndpoint?: string) => Promise<{
|
|
12
13
|
lendingMarket: {
|
|
13
14
|
version: bigint;
|
|
14
15
|
reserves: {
|
|
@@ -105,17 +106,17 @@ export declare const initializeSuilend: (suiClient: SuiJsonRpcClient, suilendCli
|
|
|
105
106
|
depositAprPercent: BigNumber;
|
|
106
107
|
utilizationPercent: BigNumber;
|
|
107
108
|
token: {
|
|
109
|
+
id: string | null;
|
|
108
110
|
decimals: number;
|
|
109
|
-
description: string;
|
|
110
|
-
iconUrl?: string | null;
|
|
111
|
-
id?: string | null;
|
|
112
111
|
name: string;
|
|
113
112
|
symbol: string;
|
|
113
|
+
description: string;
|
|
114
|
+
iconUrl: string | null;
|
|
114
115
|
coinType: string;
|
|
115
116
|
};
|
|
116
117
|
symbol: string;
|
|
117
118
|
name: string;
|
|
118
|
-
iconUrl: string | null
|
|
119
|
+
iconUrl: string | null;
|
|
119
120
|
description: string;
|
|
120
121
|
totalDeposits: BigNumber;
|
|
121
122
|
}[];
|
|
@@ -145,7 +146,7 @@ export declare const initializeSuilend: (suiClient: SuiJsonRpcClient, suilendCli
|
|
|
145
146
|
totalSupplyUsd: BigNumber;
|
|
146
147
|
totalBorrowUsd: BigNumber;
|
|
147
148
|
};
|
|
148
|
-
coinMetadataMap: Record<string, CoinMetadata>;
|
|
149
|
+
coinMetadataMap: Record<string, SuiClientTypes.CoinMetadata>;
|
|
149
150
|
refreshedRawReserves: Reserve<string>[];
|
|
150
151
|
reserveMap: Record<string, {
|
|
151
152
|
config: {
|
|
@@ -241,17 +242,17 @@ export declare const initializeSuilend: (suiClient: SuiJsonRpcClient, suilendCli
|
|
|
241
242
|
depositAprPercent: BigNumber;
|
|
242
243
|
utilizationPercent: BigNumber;
|
|
243
244
|
token: {
|
|
245
|
+
id: string | null;
|
|
244
246
|
decimals: number;
|
|
245
|
-
description: string;
|
|
246
|
-
iconUrl?: string | null;
|
|
247
|
-
id?: string | null;
|
|
248
247
|
name: string;
|
|
249
248
|
symbol: string;
|
|
249
|
+
description: string;
|
|
250
|
+
iconUrl: string | null;
|
|
250
251
|
coinType: string;
|
|
251
252
|
};
|
|
252
253
|
symbol: string;
|
|
253
254
|
name: string;
|
|
254
|
-
iconUrl: string | null
|
|
255
|
+
iconUrl: string | null;
|
|
255
256
|
description: string;
|
|
256
257
|
totalDeposits: BigNumber;
|
|
257
258
|
}>;
|
|
@@ -264,7 +265,7 @@ export declare const initializeSuilend: (suiClient: SuiJsonRpcClient, suilendCli
|
|
|
264
265
|
export declare const initializeSuilendRewards: (reserveMap: Record<string, ParsedReserve>, activeRewardCoinTypes: string[]) => Promise<{
|
|
265
266
|
rewardPriceMap: Record<string, BigNumber | undefined>;
|
|
266
267
|
}>;
|
|
267
|
-
export declare const initializeObligations: (
|
|
268
|
+
export declare const initializeObligations: (suiGrpcClient: SuiGrpcClient, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>, address?: string) => Promise<{
|
|
268
269
|
strategyOwnerCaps: StrategyOwnerCap[];
|
|
269
270
|
strategyObligations: {
|
|
270
271
|
id: string;
|
|
@@ -381,17 +382,17 @@ export declare const initializeObligations: (suiClient: SuiJsonRpcClient, suilen
|
|
|
381
382
|
depositAprPercent: BigNumber;
|
|
382
383
|
utilizationPercent: BigNumber;
|
|
383
384
|
token: {
|
|
385
|
+
id: string | null;
|
|
384
386
|
decimals: number;
|
|
385
|
-
description: string;
|
|
386
|
-
iconUrl?: string | null;
|
|
387
|
-
id?: string | null;
|
|
388
387
|
name: string;
|
|
389
388
|
symbol: string;
|
|
389
|
+
description: string;
|
|
390
|
+
iconUrl: string | null;
|
|
390
391
|
coinType: string;
|
|
391
392
|
};
|
|
392
393
|
symbol: string;
|
|
393
394
|
name: string;
|
|
394
|
-
iconUrl: string | null
|
|
395
|
+
iconUrl: string | null;
|
|
395
396
|
description: string;
|
|
396
397
|
totalDeposits: BigNumber;
|
|
397
398
|
};
|
|
@@ -498,17 +499,17 @@ export declare const initializeObligations: (suiClient: SuiJsonRpcClient, suilen
|
|
|
498
499
|
depositAprPercent: BigNumber;
|
|
499
500
|
utilizationPercent: BigNumber;
|
|
500
501
|
token: {
|
|
502
|
+
id: string | null;
|
|
501
503
|
decimals: number;
|
|
502
|
-
description: string;
|
|
503
|
-
iconUrl?: string | null;
|
|
504
|
-
id?: string | null;
|
|
505
504
|
name: string;
|
|
506
505
|
symbol: string;
|
|
506
|
+
description: string;
|
|
507
|
+
iconUrl: string | null;
|
|
507
508
|
coinType: string;
|
|
508
509
|
};
|
|
509
510
|
symbol: string;
|
|
510
511
|
name: string;
|
|
511
|
-
iconUrl: string | null
|
|
512
|
+
iconUrl: string | null;
|
|
512
513
|
description: string;
|
|
513
514
|
totalDeposits: BigNumber;
|
|
514
515
|
};
|
|
@@ -639,17 +640,17 @@ export declare const initializeObligations: (suiClient: SuiJsonRpcClient, suilen
|
|
|
639
640
|
depositAprPercent: BigNumber;
|
|
640
641
|
utilizationPercent: BigNumber;
|
|
641
642
|
token: {
|
|
643
|
+
id: string | null;
|
|
642
644
|
decimals: number;
|
|
643
|
-
description: string;
|
|
644
|
-
iconUrl?: string | null;
|
|
645
|
-
id?: string | null;
|
|
646
645
|
name: string;
|
|
647
646
|
symbol: string;
|
|
647
|
+
description: string;
|
|
648
|
+
iconUrl: string | null;
|
|
648
649
|
coinType: string;
|
|
649
650
|
};
|
|
650
651
|
symbol: string;
|
|
651
652
|
name: string;
|
|
652
|
-
iconUrl: string | null
|
|
653
|
+
iconUrl: string | null;
|
|
653
654
|
description: string;
|
|
654
655
|
totalDeposits: BigNumber;
|
|
655
656
|
};
|
|
@@ -756,17 +757,17 @@ export declare const initializeObligations: (suiClient: SuiJsonRpcClient, suilen
|
|
|
756
757
|
depositAprPercent: BigNumber;
|
|
757
758
|
utilizationPercent: BigNumber;
|
|
758
759
|
token: {
|
|
760
|
+
id: string | null;
|
|
759
761
|
decimals: number;
|
|
760
|
-
description: string;
|
|
761
|
-
iconUrl?: string | null;
|
|
762
|
-
id?: string | null;
|
|
763
762
|
name: string;
|
|
764
763
|
symbol: string;
|
|
764
|
+
description: string;
|
|
765
|
+
iconUrl: string | null;
|
|
765
766
|
coinType: string;
|
|
766
767
|
};
|
|
767
768
|
symbol: string;
|
|
768
769
|
name: string;
|
|
769
|
-
iconUrl: string | null
|
|
770
|
+
iconUrl: string | null;
|
|
770
771
|
description: string;
|
|
771
772
|
totalDeposits: BigNumber;
|
|
772
773
|
};
|