@suilend/sdk 1.1.13 → 1.1.15
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/client.d.ts +10 -11
- package/client.js +50 -69
- package/constants.js +1 -0
- package/package.json +1 -1
package/client.d.ts
CHANGED
|
@@ -16,11 +16,10 @@ export declare class SuilendClient {
|
|
|
16
16
|
constructor(lendingMarket: LendingMarket<string>, client: SuiClient);
|
|
17
17
|
static initialize(lendingMarketId: string, lendingMarketType: string, client: SuiClient): Promise<SuilendClient>;
|
|
18
18
|
static initializeWithLendingMarket(lendingMarket: LendingMarket<string>, client: SuiClient): Promise<SuilendClient>;
|
|
19
|
-
static
|
|
20
|
-
static createNewLendingMarket(registryId: string, lendingMarketType: string, transaction: Transaction): Promise<{
|
|
19
|
+
static createNewLendingMarket(registryId: string, lendingMarketType: string, transaction: Transaction): {
|
|
21
20
|
$kind: "NestedResult";
|
|
22
21
|
NestedResult: [number, number];
|
|
23
|
-
}
|
|
22
|
+
};
|
|
24
23
|
static getObligationOwnerCaps(ownerId: string, lendingMarketTypeArgs: string[], client: SuiClient): Promise<ObligationOwnerCap<string>[]>;
|
|
25
24
|
static getObligation(obligationId: string, lendingMarketTypeArgs: string[], client: SuiClient): Promise<Obligation<string>>;
|
|
26
25
|
getObligation(obligationId: string): Promise<Obligation<string>>;
|
|
@@ -31,18 +30,18 @@ export declare class SuilendClient {
|
|
|
31
30
|
cancelReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
|
|
32
31
|
closeReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
|
|
33
32
|
claimReward(obligationOwnerCapId: string, reserveArrayIndex: bigint, rewardIndex: bigint, rewardType: string, side: Side, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
claimRewardAndDeposit(obligationId: string, rewardReserveArrayIndex: bigint, rewardIndex: bigint, rewardType: string, side: Side, depositReserveArrayIndex: bigint, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
|
|
34
|
+
claimRewardsAndSendToUser(ownerId: string, rewards: {
|
|
36
35
|
obligationOwnerCapId: string;
|
|
37
36
|
reserveArrayIndex: bigint;
|
|
38
37
|
rewardIndex: bigint;
|
|
39
38
|
rewardType: string;
|
|
40
39
|
side: Side;
|
|
41
|
-
}[], transaction: Transaction):
|
|
40
|
+
}[], transaction: Transaction): void;
|
|
42
41
|
findReserveArrayIndex(coinType: string): bigint;
|
|
43
|
-
updateReserveConfig(
|
|
44
|
-
newObligationOwnerCap(transaction: Transaction, lendingMarketOwnerCapId: string, destinationAddress: string, obligationId: string):
|
|
45
|
-
updateRateLimiterConfig(lendingMarketOwnerCapId: string, transaction: Transaction, newRateLimiterConfigArgs: CreateRateLimiterConfigArgs):
|
|
42
|
+
updateReserveConfig(lendingMarketOwnerCapId: string, transaction: Transaction, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs): import("@mysten/sui/transactions").TransactionResult;
|
|
43
|
+
newObligationOwnerCap(transaction: Transaction, lendingMarketOwnerCapId: string, destinationAddress: string, obligationId: string): void;
|
|
44
|
+
updateRateLimiterConfig(lendingMarketOwnerCapId: string, transaction: Transaction, newRateLimiterConfigArgs: CreateRateLimiterConfigArgs): import("@mysten/sui/transactions").TransactionResult;
|
|
46
45
|
changeReservePriceFeed(lendingMarketOwnerCapId: string, coinType: string, pythPriceId: string, transaction: Transaction): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
|
47
46
|
createObligation(transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
|
|
48
47
|
refreshAll(transaction: Transaction, obligation: Obligation<string>, extraReserveArrayIndex?: bigint): Promise<void>;
|
|
@@ -52,9 +51,9 @@ export declare class SuilendClient {
|
|
|
52
51
|
depositIntoObligation(ownerId: string, coinType: string, value: string, transaction: Transaction, obligationOwnerCapId?: string): Promise<void>;
|
|
53
52
|
depositLiquidityAndGetCTokens(ownerId: string, coinType: string, value: string, transaction: Transaction): Promise<void>;
|
|
54
53
|
withdraw(obligationOwnerCapId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
|
55
|
-
|
|
54
|
+
withdrawAndSendToUser(ownerId: string, obligationOwnerCapId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<void>;
|
|
56
55
|
borrow(obligationOwnerCapId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
|
57
|
-
|
|
56
|
+
borrowAndSendToUser(ownerId: string, obligationOwnerCapId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<void>;
|
|
58
57
|
repay(obligationId: string, coinType: string, coin: TransactionObjectInput, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
|
|
59
58
|
repayIntoObligation(ownerId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
|
60
59
|
liquidateAndRedeem(transaction: Transaction, obligation: Obligation<string>, repayCoinType: string, withdrawCoinType: string, repayCoinId: TransactionObjectInput): Promise<import("@mysten/sui/transactions").TransactionResult>;
|
package/client.js
CHANGED
|
@@ -60,31 +60,19 @@ class SuilendClient {
|
|
|
60
60
|
static initializeWithLendingMarket(lendingMarket, client) {
|
|
61
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
62
|
const latestPackageId = yield getLatestPackageId(client, SUILEND_UPGRADE_CAP_ID);
|
|
63
|
+
console.log("latestPackageId", latestPackageId);
|
|
63
64
|
(0, suilend_1.setPublishedAt)(latestPackageId);
|
|
64
65
|
return new SuilendClient(lendingMarket, client);
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
|
-
static hasBetaPass(ownerId, client) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const objs = yield client.getOwnedObjects({
|
|
70
|
-
owner: ownerId,
|
|
71
|
-
filter: {
|
|
72
|
-
StructType: "0x02fb1289eb4e9ef987c6e383be4a9b298ef96d10a3f29060aaef39a0f9ecfbe6::suilend_beta_pass::SuilendBetaPass",
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
return objs.data.length > 0;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
68
|
static createNewLendingMarket(registryId, lendingMarketType, transaction) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
arguments: [lendingMarket],
|
|
85
|
-
});
|
|
86
|
-
return ownerCap;
|
|
69
|
+
const [ownerCap, lendingMarket] = (0, functions_2.createLendingMarket)(transaction, lendingMarketType, transaction.object(registryId));
|
|
70
|
+
transaction.moveCall({
|
|
71
|
+
target: `0x2::transfer::public_share_object`,
|
|
72
|
+
typeArguments: [`${structs_1.LendingMarket.$typeName}<${lendingMarketType}>}`],
|
|
73
|
+
arguments: [lendingMarket],
|
|
87
74
|
});
|
|
75
|
+
return ownerCap;
|
|
88
76
|
}
|
|
89
77
|
static getObligationOwnerCaps(ownerId, lendingMarketTypeArgs, client) {
|
|
90
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -131,7 +119,9 @@ class SuilendClient {
|
|
|
131
119
|
});
|
|
132
120
|
}
|
|
133
121
|
getObligation(obligationId) {
|
|
134
|
-
return
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
return SuilendClient.getObligation(obligationId, this.lendingMarket.$typeArgs, this.client);
|
|
124
|
+
});
|
|
135
125
|
}
|
|
136
126
|
static getLendingMarketOwnerCapId(ownerId, lendingMarketTypeArgs, client) {
|
|
137
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -229,10 +219,10 @@ class SuilendClient {
|
|
|
229
219
|
isDepositReward: transaction.pure.bool(side === types_1.Side.DEPOSIT),
|
|
230
220
|
});
|
|
231
221
|
}
|
|
232
|
-
|
|
222
|
+
claimRewardAndDeposit(obligationId, rewardReserveArrayIndex, rewardIndex, rewardType, side, depositReserveArrayIndex, transaction) {
|
|
233
223
|
return (0, functions_1.claimRewardsAndDeposit)(transaction, [this.lendingMarket.$typeArgs[0], rewardType], {
|
|
234
224
|
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
235
|
-
obligationId,
|
|
225
|
+
obligationId: transaction.pure.id(obligationId),
|
|
236
226
|
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
237
227
|
rewardReserveId: transaction.pure.u64(rewardReserveArrayIndex),
|
|
238
228
|
rewardIndex: transaction.pure.u64(rewardIndex),
|
|
@@ -240,59 +230,50 @@ class SuilendClient {
|
|
|
240
230
|
depositReserveId: transaction.pure.u64(depositReserveArrayIndex),
|
|
241
231
|
});
|
|
242
232
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
233
|
+
claimRewardsAndSendToUser(ownerId, rewards, transaction) {
|
|
234
|
+
const mergeCoinsMap = {};
|
|
235
|
+
for (const reward of rewards) {
|
|
236
|
+
const [claimedCoin] = this.claimReward(reward.obligationOwnerCapId, reward.reserveArrayIndex, reward.rewardIndex, reward.rewardType, reward.side, transaction);
|
|
237
|
+
if (mergeCoinsMap[reward.rewardType] === undefined)
|
|
238
|
+
mergeCoinsMap[reward.rewardType] = [];
|
|
239
|
+
mergeCoinsMap[reward.rewardType].push(claimedCoin);
|
|
240
|
+
}
|
|
241
|
+
for (const mergeCoins of Object.values(mergeCoinsMap)) {
|
|
242
|
+
const mergeCoin = mergeCoins[0];
|
|
243
|
+
if (mergeCoins.length > 1) {
|
|
244
|
+
transaction.mergeCoins(mergeCoin, mergeCoins.slice(1));
|
|
251
245
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (mergeCoins.length > 1) {
|
|
255
|
-
transaction.mergeCoins(mergeCoin, mergeCoins.slice(1));
|
|
256
|
-
}
|
|
257
|
-
transaction.transferObjects([mergeCoin], transaction.pure.address(ownerId));
|
|
258
|
-
}
|
|
259
|
-
});
|
|
246
|
+
transaction.transferObjects([mergeCoin], transaction.pure.address(ownerId));
|
|
247
|
+
}
|
|
260
248
|
}
|
|
261
249
|
findReserveArrayIndex(coinType) {
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
return BigInt(array_index);
|
|
250
|
+
const arrayIndex = this.lendingMarket.reserves.findIndex((r) => (0, utils_1.normalizeStructTag)(r.coinType.name) === (0, utils_1.normalizeStructTag)(coinType));
|
|
251
|
+
return BigInt(arrayIndex);
|
|
265
252
|
}
|
|
266
|
-
updateReserveConfig(
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
config: transaction.object(config),
|
|
274
|
-
});
|
|
253
|
+
updateReserveConfig(lendingMarketOwnerCapId, transaction, coinType, createReserveConfigArgs) {
|
|
254
|
+
const [config] = (0, functions_4.createReserveConfig)(transaction, createReserveConfigArgs);
|
|
255
|
+
return (0, functions_1.updateReserveConfig)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
256
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
257
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
258
|
+
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
259
|
+
config: transaction.object(config),
|
|
275
260
|
});
|
|
276
261
|
}
|
|
277
262
|
newObligationOwnerCap(transaction, lendingMarketOwnerCapId, destinationAddress, obligationId) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
obligationId,
|
|
283
|
-
});
|
|
284
|
-
transaction.transferObjects([obligationOwnerCap], transaction.pure.address(destinationAddress));
|
|
263
|
+
const [obligationOwnerCap] = (0, functions_1.newObligationOwnerCap)(transaction, this.lendingMarket.$typeArgs[0], {
|
|
264
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
265
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
266
|
+
obligationId: transaction.pure.id(obligationId),
|
|
285
267
|
});
|
|
268
|
+
transaction.transferObjects([obligationOwnerCap], transaction.pure.address(destinationAddress));
|
|
286
269
|
}
|
|
287
270
|
updateRateLimiterConfig(lendingMarketOwnerCapId, transaction, newRateLimiterConfigArgs) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
config: transaction.object(config),
|
|
295
|
-
});
|
|
271
|
+
const [config] = (0, functions_3.newConfig)(transaction, newRateLimiterConfigArgs);
|
|
272
|
+
return (0, functions_1.updateRateLimiterConfig)(transaction, this.lendingMarket.$typeArgs[0], {
|
|
273
|
+
lendingMarketOwnerCap: transaction.object(lendingMarketOwnerCapId),
|
|
274
|
+
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
275
|
+
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
276
|
+
config: transaction.object(config),
|
|
296
277
|
});
|
|
297
278
|
}
|
|
298
279
|
changeReservePriceFeed(lendingMarketOwnerCapId, coinType, pythPriceId, transaction) {
|
|
@@ -454,7 +435,7 @@ class SuilendClient {
|
|
|
454
435
|
});
|
|
455
436
|
});
|
|
456
437
|
}
|
|
457
|
-
|
|
438
|
+
withdrawAndSendToUser(ownerId, obligationOwnerCapId, obligationId, coinType, value, transaction) {
|
|
458
439
|
return __awaiter(this, void 0, void 0, function* () {
|
|
459
440
|
const [withdrawCoin] = yield this.withdraw(obligationOwnerCapId, obligationId, coinType, value, transaction);
|
|
460
441
|
transaction.transferObjects([withdrawCoin], transaction.pure.address(ownerId));
|
|
@@ -476,7 +457,7 @@ class SuilendClient {
|
|
|
476
457
|
return result;
|
|
477
458
|
});
|
|
478
459
|
}
|
|
479
|
-
|
|
460
|
+
borrowAndSendToUser(ownerId, obligationOwnerCapId, obligationId, coinType, value, transaction) {
|
|
480
461
|
return __awaiter(this, void 0, void 0, function* () {
|
|
481
462
|
const [borrowCoin] = yield this.borrow(obligationOwnerCapId, obligationId, coinType, value, transaction);
|
|
482
463
|
transaction.transferObjects([borrowCoin], transaction.pure.address(ownerId));
|
|
@@ -486,7 +467,7 @@ class SuilendClient {
|
|
|
486
467
|
return (0, functions_1.repay)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
|
|
487
468
|
lendingMarket: transaction.object(this.lendingMarket.id),
|
|
488
469
|
reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
|
|
489
|
-
obligationId: obligationId,
|
|
470
|
+
obligationId: transaction.pure.id(obligationId),
|
|
490
471
|
clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
491
472
|
maxRepayCoins: coin,
|
|
492
473
|
});
|
|
@@ -504,7 +485,7 @@ class SuilendClient {
|
|
|
504
485
|
}
|
|
505
486
|
const [sendCoin] = transaction.splitCoins(isSui ? transaction.gas : transaction.object(mergeCoin.coinObjectId), [value]);
|
|
506
487
|
const result = this.repay(obligationId, coinType, sendCoin, transaction);
|
|
507
|
-
transaction.transferObjects([sendCoin], ownerId);
|
|
488
|
+
transaction.transferObjects([sendCoin], transaction.pure.address(ownerId));
|
|
508
489
|
return result;
|
|
509
490
|
});
|
|
510
491
|
}
|
package/constants.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sdk","version":"1.1.
|
|
1
|
+
{"name":"@suilend/sdk","version":"1.1.15","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","./constants":"./constants.js","./types":"./types.js","./api/events":"./api/events.js","./api":"./api/index.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/price-identifier/structs":"./_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/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":{"@mysten/bcs":"1.1.0","@mysten/sui":"1.14.2","@pythnetwork/pyth-sui-js":"^2.1.0","bignumber.js":"^9.1.2","p-limit":"^3.1.0","uuid":"^9.0.1"},"devDependencies":{"ts-node":"^10.9.2"}}
|