@suilend/sdk 1.1.73 → 1.1.74

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SuiClient } from "@mysten/sui/client";
2
- import { Transaction, TransactionObjectArgument, TransactionObjectInput, TransactionResult } from "@mysten/sui/transactions";
2
+ import { Transaction, TransactionObjectArgument, TransactionObjectInput } from "@mysten/sui/transactions";
3
3
  import { SuiPriceServiceConnection, SuiPythClient } from "@pythnetwork/pyth-sui-js";
4
4
  import { FeeReceivers, LendingMarket, ObligationOwnerCap } from "./_generated/suilend/lending-market/structs";
5
5
  import { Obligation } from "./_generated/suilend/obligation/structs";
@@ -52,41 +52,41 @@ export declare class SuilendClient {
52
52
  getObligation(obligationId: string): Promise<Obligation<string>>;
53
53
  static getLendingMarketOwnerCapId(ownerId: string, lendingMarketTypeArgs: string[], client: SuiClient): Promise<string | undefined>;
54
54
  getLendingMarketOwnerCapId(ownerId: string): Promise<string | undefined>;
55
- createReserve(lendingMarketOwnerCapId: string, transaction: Transaction, pythPriceId: string, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs): Promise<TransactionResult>;
56
- addReward(ownerId: string, lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardCoinType: string, rewardValue: string, startTimeMs: bigint, endTimeMs: bigint, transaction: Transaction, mergeCoins?: boolean): Promise<TransactionResult>;
57
- cancelReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): TransactionResult;
58
- closeReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): TransactionResult;
59
- claimReward(obligationOwnerCapId: string, reserveArrayIndex: bigint, rewardIndex: bigint, rewardType: string, side: Side, transaction: Transaction): TransactionResult;
60
- claimRewardAndDeposit(obligationId: string, rewardReserveArrayIndex: bigint, rewardIndex: bigint, rewardCoinType: string, side: Side, depositReserveArrayIndex: bigint, transaction: Transaction): TransactionResult;
61
- claimRewards(ownerId: string, obligationOwnerCapId: string, rewards: ClaimRewardsReward[], transaction: Transaction): {
55
+ createReserve(lendingMarketOwnerCapId: string, transaction: Transaction, pythPriceId: string, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs): Promise<import("@mysten/sui/transactions").TransactionResult>;
56
+ 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>;
57
+ cancelReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
58
+ closeReward(lendingMarketOwnerCapId: string, reserveArrayIndex: bigint, isDepositReward: boolean, rewardIndex: bigint, rewardCoinType: string, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
59
+ claimReward(obligationOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, rewardIndex: bigint, rewardType: string, side: Side, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
60
+ claimRewardAndDeposit(obligationId: string, rewardReserveArrayIndex: bigint, rewardIndex: bigint, rewardCoinType: string, side: Side, depositReserveArrayIndex: bigint, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
61
+ claimRewards(ownerId: string, obligationOwnerCap: TransactionObjectInput, rewards: ClaimRewardsReward[], transaction: Transaction): {
62
62
  transaction: Transaction;
63
63
  mergedCoinsMap: Record<string, TransactionObjectArgument>;
64
64
  };
65
- claimRewardsAndSendToUser(ownerId: string, obligationOwnerCapId: string, rewards: ClaimRewardsReward[], transaction: Transaction): Transaction;
66
- claimRewardsAndDeposit(ownerId: string, obligationOwnerCapId: string, rewards: ClaimRewardsReward[], transaction: Transaction): Transaction;
65
+ claimRewardsAndSendToUser(ownerId: string, obligationOwnerCap: TransactionObjectInput, rewards: ClaimRewardsReward[], transaction: Transaction): Transaction;
66
+ claimRewardsAndDeposit(ownerId: string, obligationOwnerCap: TransactionObjectInput, rewards: ClaimRewardsReward[], transaction: Transaction): Transaction;
67
67
  findReserveArrayIndex(coinType: string): bigint;
68
- updateReserveConfig(lendingMarketOwnerCapId: string, transaction: Transaction, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs): TransactionResult;
68
+ updateReserveConfig(lendingMarketOwnerCapId: string, transaction: Transaction, coinType: string, createReserveConfigArgs: CreateReserveConfigArgs): import("@mysten/sui/transactions").TransactionResult;
69
69
  newObligationOwnerCap(transaction: Transaction, lendingMarketOwnerCapId: string, destinationAddress: string, obligationId: string): void;
70
- updateRateLimiterConfig(lendingMarketOwnerCapId: string, transaction: Transaction, newRateLimiterConfigArgs: CreateRateLimiterConfigArgs): TransactionResult;
71
- changeReservePriceFeed(lendingMarketOwnerCapId: string, coinType: string, pythPriceId: string, transaction: Transaction): Promise<TransactionResult>;
72
- createObligation(transaction: Transaction): TransactionResult;
73
- refreshAll(transaction: Transaction, obligation: Obligation<string>, extraReserveArrayIndex?: bigint): Promise<void>;
70
+ updateRateLimiterConfig(lendingMarketOwnerCapId: string, transaction: Transaction, newRateLimiterConfigArgs: CreateRateLimiterConfigArgs): import("@mysten/sui/transactions").TransactionResult;
71
+ changeReservePriceFeed(lendingMarketOwnerCapId: string, coinType: string, pythPriceId: string, transaction: Transaction): Promise<import("@mysten/sui/transactions").TransactionResult>;
72
+ createObligation(transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
73
+ refreshAll(transaction: Transaction, obligation?: Obligation<string>, coinTypes?: string[]): Promise<void>;
74
74
  refreshReservePrices(transaction: Transaction, priceInfoObjectId: string, reserveArrayIndex: bigint): Promise<void>;
75
75
  deposit(sendCoin: TransactionObjectInput, coinType: string, obligationOwnerCap: TransactionObjectInput, transaction: Transaction): void;
76
- depositIntoObligation(ownerId: string, coinType: string, value: string, transaction: Transaction, obligationOwnerCapId: string | TransactionResult): Promise<void>;
76
+ depositIntoObligation(ownerId: string, coinType: string, value: string, transaction: Transaction, obligationOwnerCap: TransactionObjectInput): Promise<void>;
77
77
  depositLiquidityAndGetCTokens(ownerId: string, coinType: string, value: string, transaction: Transaction): Promise<void>;
78
- withdraw(obligationOwnerCapId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<TransactionResult>;
79
- redeem(ctokens: TransactionObjectInput, coinType: string, exemption: TransactionObjectInput, transaction: Transaction): TransactionResult;
80
- withdrawAndSendToUser(ownerId: string, obligationOwnerCapId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<void>;
81
- borrow(obligationOwnerCapId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<TransactionResult>;
82
- borrowAndSendToUser(ownerId: string, obligationOwnerCapId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<void>;
83
- repay(obligationId: string, coinType: string, coin: TransactionObjectInput, transaction: Transaction): TransactionResult;
84
- repayIntoObligation(ownerId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<TransactionResult>;
85
- liquidateAndRedeem(transaction: Transaction, obligation: Obligation<string>, repayCoinType: string, withdrawCoinType: string, repayCoinId: TransactionObjectInput): Promise<TransactionResult>;
86
- liquidate(transaction: Transaction, obligation: Obligation<string>, repayCoinType: string, withdrawCoinType: string, repayCoinId: TransactionObjectInput): Promise<TransactionResult>;
87
- migrate(transaction: Transaction, lendingMarketOwnerCapId: string): TransactionResult;
88
- claimFees(transaction: Transaction, coinType: string): TransactionResult;
89
- setFeeReceiversAndWeights(transaction: Transaction, lendingMarketOwnerCapId: string, receivers: string[], weights: bigint[]): TransactionResult;
78
+ withdraw(obligationOwnerCap: TransactionObjectInput, obligationId: string, coinType: string, value: string, transaction: Transaction, addRefreshCalls?: boolean): Promise<import("@mysten/sui/transactions").TransactionResult>;
79
+ redeem(ctokens: TransactionObjectInput, coinType: string, exemption: TransactionObjectInput, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
80
+ withdrawAndSendToUser(ownerId: string, obligationOwnerCap: TransactionObjectInput, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<void>;
81
+ borrow(obligationOwnerCap: TransactionObjectInput, obligationId: string, coinType: string, value: string, transaction: Transaction, addRefreshCalls?: boolean): Promise<import("@mysten/sui/transactions").TransactionResult>;
82
+ borrowAndSendToUser(ownerId: string, obligationOwnerCap: TransactionObjectInput, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<void>;
83
+ repay(obligationId: string, coinType: string, coin: TransactionObjectInput, transaction: Transaction): import("@mysten/sui/transactions").TransactionResult;
84
+ repayIntoObligation(ownerId: string, obligationId: string, coinType: string, value: string, transaction: Transaction): Promise<import("@mysten/sui/transactions").TransactionResult>;
85
+ liquidateAndRedeem(transaction: Transaction, obligation: Obligation<string>, repayCoinType: string, withdrawCoinType: string, repayCoinId: TransactionObjectInput): Promise<import("@mysten/sui/transactions").TransactionResult>;
86
+ liquidate(transaction: Transaction, obligation: Obligation<string>, repayCoinType: string, withdrawCoinType: string, repayCoinId: TransactionObjectInput): Promise<import("@mysten/sui/transactions").TransactionResult>;
87
+ migrate(transaction: Transaction, lendingMarketOwnerCapId: string): import("@mysten/sui/transactions").TransactionResult;
88
+ claimFees(transaction: Transaction, coinType: string): import("@mysten/sui/transactions").TransactionResult;
89
+ setFeeReceiversAndWeights(transaction: Transaction, lendingMarketOwnerCapId: string, receivers: string[], weights: bigint[]): import("@mysten/sui/transactions").TransactionResult;
90
90
  redeemCtokensAndWithdrawLiquidity(ownerId: string, ctokenCoinTypes: string[], transaction: Transaction): Promise<void>;
91
91
  }
92
92
  export {};
package/client.js CHANGED
@@ -282,10 +282,10 @@ class SuilendClient {
282
282
  clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
283
283
  });
284
284
  }
285
- claimReward(obligationOwnerCapId, reserveArrayIndex, rewardIndex, rewardType, side, transaction) {
285
+ claimReward(obligationOwnerCap, reserveArrayIndex, rewardIndex, rewardType, side, transaction) {
286
286
  return (0, functions_1.claimRewards)(transaction, [this.lendingMarket.$typeArgs[0], rewardType], {
287
287
  lendingMarket: transaction.object(this.lendingMarket.id),
288
- cap: transaction.object(obligationOwnerCapId),
288
+ cap: transaction.object(obligationOwnerCap),
289
289
  clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
290
290
  reserveId: transaction.pure.u64(reserveArrayIndex),
291
291
  rewardIndex: transaction.pure.u64(rewardIndex),
@@ -303,10 +303,10 @@ class SuilendClient {
303
303
  depositReserveId: transaction.pure.u64(depositReserveArrayIndex),
304
304
  });
305
305
  }
306
- claimRewards(ownerId, obligationOwnerCapId, rewards, transaction) {
306
+ claimRewards(ownerId, obligationOwnerCap, rewards, transaction) {
307
307
  const mergeCoinsMap = {};
308
308
  for (const reward of rewards) {
309
- const [claimedCoin] = this.claimReward(obligationOwnerCapId, reward.reserveArrayIndex, reward.rewardIndex, reward.rewardCoinType, reward.side, transaction);
309
+ const [claimedCoin] = this.claimReward(obligationOwnerCap, reward.reserveArrayIndex, reward.rewardIndex, reward.rewardCoinType, reward.side, transaction);
310
310
  if (mergeCoinsMap[reward.rewardCoinType] === undefined)
311
311
  mergeCoinsMap[reward.rewardCoinType] = [];
312
312
  mergeCoinsMap[reward.rewardCoinType].push(claimedCoin);
@@ -320,17 +320,17 @@ class SuilendClient {
320
320
  }
321
321
  return { transaction, mergedCoinsMap };
322
322
  }
323
- claimRewardsAndSendToUser(ownerId, obligationOwnerCapId, rewards, transaction) {
324
- const { transaction: transaction_, mergedCoinsMap } = this.claimRewards(ownerId, obligationOwnerCapId, rewards, transaction);
323
+ claimRewardsAndSendToUser(ownerId, obligationOwnerCap, rewards, transaction) {
324
+ const { transaction: transaction_, mergedCoinsMap } = this.claimRewards(ownerId, obligationOwnerCap, rewards, transaction);
325
325
  for (const [coinType, coin] of Object.entries(mergedCoinsMap)) {
326
326
  transaction_.transferObjects([coin], transaction_.pure.address(ownerId));
327
327
  }
328
328
  return transaction_;
329
329
  }
330
- claimRewardsAndDeposit(ownerId, obligationOwnerCapId, rewards, transaction) {
331
- const { transaction: transaction_, mergedCoinsMap } = this.claimRewards(ownerId, obligationOwnerCapId, rewards, transaction);
330
+ claimRewardsAndDeposit(ownerId, obligationOwnerCap, rewards, transaction) {
331
+ const { transaction: transaction_, mergedCoinsMap } = this.claimRewards(ownerId, obligationOwnerCap, rewards, transaction);
332
332
  for (const [coinType, coin] of Object.entries(mergedCoinsMap)) {
333
- this.deposit(coin, coinType, obligationOwnerCapId, transaction_);
333
+ this.deposit(coin, coinType, obligationOwnerCap, transaction_);
334
334
  }
335
335
  return transaction_;
336
336
  }
@@ -386,22 +386,28 @@ class SuilendClient {
386
386
  typeArguments: this.lendingMarket.$typeArgs,
387
387
  });
388
388
  }
389
- refreshAll(transaction, obligation, extraReserveArrayIndex) {
389
+ refreshAll(transaction, obligation, coinTypes) {
390
390
  return __awaiter(this, void 0, void 0, function* () {
391
391
  const reserveArrayIndexToPriceId = new Map();
392
- obligation.deposits.forEach((deposit) => {
393
- const reserve = this.lendingMarket.reserves[Number(deposit.reserveArrayIndex)];
394
- reserveArrayIndexToPriceId.set(deposit.reserveArrayIndex, (0, utils_1.toHEX)(new Uint8Array(reserve.priceIdentifier.bytes)));
395
- });
396
- obligation.borrows.forEach((borrow) => {
397
- const reserve = this.lendingMarket.reserves[Number(borrow.reserveArrayIndex)];
398
- reserveArrayIndexToPriceId.set(borrow.reserveArrayIndex, (0, utils_1.toHEX)(new Uint8Array(reserve.priceIdentifier.bytes)));
399
- });
400
- if (extraReserveArrayIndex != undefined &&
401
- extraReserveArrayIndex >= 0 &&
402
- extraReserveArrayIndex < this.lendingMarket.reserves.length) {
403
- const reserve = this.lendingMarket.reserves[Number(extraReserveArrayIndex)];
404
- reserveArrayIndexToPriceId.set(extraReserveArrayIndex, (0, utils_1.toHEX)(new Uint8Array(reserve.priceIdentifier.bytes)));
392
+ if (obligation) {
393
+ obligation.deposits.forEach((deposit) => {
394
+ const reserve = this.lendingMarket.reserves[Number(deposit.reserveArrayIndex)];
395
+ reserveArrayIndexToPriceId.set(deposit.reserveArrayIndex, (0, utils_1.toHEX)(new Uint8Array(reserve.priceIdentifier.bytes)));
396
+ });
397
+ obligation.borrows.forEach((borrow) => {
398
+ const reserve = this.lendingMarket.reserves[Number(borrow.reserveArrayIndex)];
399
+ reserveArrayIndexToPriceId.set(borrow.reserveArrayIndex, (0, utils_1.toHEX)(new Uint8Array(reserve.priceIdentifier.bytes)));
400
+ });
401
+ }
402
+ if (coinTypes !== undefined) {
403
+ for (const coinType of coinTypes) {
404
+ const reserveArrayIndex = this.findReserveArrayIndex(coinType);
405
+ if (reserveArrayIndex >= 0 &&
406
+ reserveArrayIndex < BigInt(this.lendingMarket.reserves.length)) {
407
+ const reserve = this.lendingMarket.reserves[Number(reserveArrayIndex)];
408
+ reserveArrayIndexToPriceId.set(reserveArrayIndex, (0, utils_1.toHEX)(new Uint8Array(reserve.priceIdentifier.bytes)));
409
+ }
410
+ }
405
411
  }
406
412
  const tuples = Array.from(reserveArrayIndexToPriceId.entries()).sort();
407
413
  const reserveArrayIndexes = tuples.map((tuple) => tuple[0]);
@@ -465,7 +471,7 @@ class SuilendClient {
465
471
  });
466
472
  }
467
473
  }
468
- depositIntoObligation(ownerId, coinType, value, transaction, obligationOwnerCapId) {
474
+ depositIntoObligation(ownerId, coinType, value, transaction, obligationOwnerCap) {
469
475
  return __awaiter(this, void 0, void 0, function* () {
470
476
  const coins = (yield this.client.getCoins({
471
477
  owner: ownerId,
@@ -478,7 +484,7 @@ class SuilendClient {
478
484
  const [sendCoin] = transaction.splitCoins(isSui(coinType)
479
485
  ? transaction.gas
480
486
  : transaction.object(mergeCoin.coinObjectId), [value]);
481
- this.deposit(sendCoin, coinType, obligationOwnerCapId, transaction);
487
+ this.deposit(sendCoin, coinType, obligationOwnerCap, transaction);
482
488
  });
483
489
  }
484
490
  depositLiquidityAndGetCTokens(ownerId, coinType, value, transaction) {
@@ -503,16 +509,18 @@ class SuilendClient {
503
509
  transaction.transferObjects([ctokens], transaction.pure.address(ownerId));
504
510
  });
505
511
  }
506
- withdraw(obligationOwnerCapId, obligationId, coinType, value, transaction) {
507
- return __awaiter(this, void 0, void 0, function* () {
508
- const obligation = yield this.getObligation(obligationId);
509
- if (!obligation)
510
- throw new Error("Error: no obligation");
511
- yield this.refreshAll(transaction, obligation);
512
+ withdraw(obligationOwnerCap_1, obligationId_1, coinType_1, value_1, transaction_1) {
513
+ return __awaiter(this, arguments, void 0, function* (obligationOwnerCap, obligationId, coinType, value, transaction, addRefreshCalls = true) {
514
+ if (addRefreshCalls) {
515
+ const obligation = yield this.getObligation(obligationId);
516
+ if (!obligation)
517
+ throw new Error("Error: no obligation");
518
+ yield this.refreshAll(transaction, obligation);
519
+ }
512
520
  const [ctokens] = (0, functions_1.withdrawCtokens)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
513
521
  lendingMarket: transaction.object(this.lendingMarket.id),
514
522
  reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
515
- obligationOwnerCap: obligationOwnerCapId,
523
+ obligationOwnerCap,
516
524
  clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
517
525
  amount: BigInt(value),
518
526
  });
@@ -548,22 +556,24 @@ class SuilendClient {
548
556
  liquidityRequest,
549
557
  });
550
558
  }
551
- withdrawAndSendToUser(ownerId, obligationOwnerCapId, obligationId, coinType, value, transaction) {
559
+ withdrawAndSendToUser(ownerId, obligationOwnerCap, obligationId, coinType, value, transaction) {
552
560
  return __awaiter(this, void 0, void 0, function* () {
553
- const [withdrawCoin] = yield this.withdraw(obligationOwnerCapId, obligationId, coinType, value, transaction);
561
+ const [withdrawCoin] = yield this.withdraw(obligationOwnerCap, obligationId, coinType, value, transaction);
554
562
  transaction.transferObjects([withdrawCoin], transaction.pure.address(ownerId));
555
563
  });
556
564
  }
557
- borrow(obligationOwnerCapId, obligationId, coinType, value, transaction) {
558
- return __awaiter(this, void 0, void 0, function* () {
559
- const obligation = yield this.getObligation(obligationId);
560
- if (!obligation)
561
- throw new Error("Error: no obligation");
562
- yield this.refreshAll(transaction, obligation, this.findReserveArrayIndex(coinType));
565
+ borrow(obligationOwnerCap_1, obligationId_1, coinType_1, value_1, transaction_1) {
566
+ return __awaiter(this, arguments, void 0, function* (obligationOwnerCap, obligationId, coinType, value, transaction, addRefreshCalls = true) {
567
+ if (addRefreshCalls) {
568
+ const obligation = yield this.getObligation(obligationId);
569
+ if (!obligation)
570
+ throw new Error("Error: no obligation");
571
+ yield this.refreshAll(transaction, obligation, [coinType]);
572
+ }
563
573
  const [liquidityRequest] = (0, functions_1.borrowRequest)(transaction, [this.lendingMarket.$typeArgs[0], coinType], {
564
574
  lendingMarket: transaction.object(this.lendingMarket.id),
565
575
  reserveArrayIndex: transaction.pure.u64(this.findReserveArrayIndex(coinType)),
566
- obligationOwnerCap: obligationOwnerCapId,
576
+ obligationOwnerCap,
567
577
  clock: transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
568
578
  amount: BigInt(value),
569
579
  });
@@ -582,9 +592,9 @@ class SuilendClient {
582
592
  });
583
593
  });
584
594
  }
585
- borrowAndSendToUser(ownerId, obligationOwnerCapId, obligationId, coinType, value, transaction) {
595
+ borrowAndSendToUser(ownerId, obligationOwnerCap, obligationId, coinType, value, transaction) {
586
596
  return __awaiter(this, void 0, void 0, function* () {
587
- const [borrowCoin] = yield this.borrow(obligationOwnerCapId, obligationId, coinType, value, transaction);
597
+ const [borrowCoin] = yield this.borrow(obligationOwnerCap, obligationId, coinType, value, transaction);
588
598
  transaction.transferObjects([borrowCoin], transaction.pure.address(ownerId));
589
599
  });
590
600
  }
@@ -3,6 +3,7 @@ import BigNumber from "bignumber.js";
3
3
  import { Reserve } from "../_generated/suilend/reserve/structs";
4
4
  import { SuilendClient } from "../client";
5
5
  import { ParsedReserve } from "../parsers";
6
+ import { StrategyOwnerCap } from "./types";
6
7
  export declare const RESERVES_CUSTOM_ORDER: string[];
7
8
  export declare const NORMALIZED_MAYA_COINTYPE: string;
8
9
  export declare const NORMALIZED_mPOINTS_COINTYPE: string;
@@ -265,6 +266,264 @@ export declare const initializeSuilendRewards: (reserveMap: Record<string, Parse
265
266
  rewardPriceMap: Record<string, BigNumber | undefined>;
266
267
  }>;
267
268
  export declare const initializeObligations: (suiClient: SuiClient, suilendClient: SuilendClient, refreshedRawReserves: Reserve<string>[], reserveMap: Record<string, ParsedReserve>, address?: string) => Promise<{
269
+ strategyOwnerCaps: StrategyOwnerCap[];
270
+ strategyObligations: {
271
+ id: string;
272
+ depositedAmountUsd: BigNumber;
273
+ borrowedAmountUsd: BigNumber;
274
+ netValueUsd: BigNumber;
275
+ weightedBorrowsUsd: BigNumber;
276
+ maxPriceWeightedBorrowsUsd: BigNumber;
277
+ borrowLimitUsd: BigNumber;
278
+ minPriceBorrowLimitUsd: BigNumber;
279
+ unhealthyBorrowValueUsd: BigNumber;
280
+ depositPositionCount: number;
281
+ borrowPositionCount: number;
282
+ positionCount: number;
283
+ deposits: {
284
+ coinType: string;
285
+ reserveArrayIndex: bigint;
286
+ userRewardManagerIndex: number;
287
+ userRewardManager: import("../_generated/suilend/liquidity-mining/structs").UserRewardManager;
288
+ depositedAmount: BigNumber;
289
+ depositedAmountUsd: BigNumber;
290
+ depositedCtokenAmount: BigNumber;
291
+ reserve: {
292
+ config: {
293
+ $typeName: string;
294
+ openLtvPct: number;
295
+ closeLtvPct: number;
296
+ maxCloseLtvPct: number;
297
+ borrowWeightBps: BigNumber;
298
+ depositLimit: BigNumber;
299
+ borrowLimit: BigNumber;
300
+ liquidationBonusBps: number;
301
+ maxLiquidationBonusBps: number;
302
+ depositLimitUsd: BigNumber;
303
+ borrowLimitUsd: BigNumber;
304
+ borrowFeeBps: number;
305
+ spreadFeeBps: number;
306
+ protocolLiquidationFeeBps: number;
307
+ isolated: boolean;
308
+ openAttributedBorrowLimitUsd: number;
309
+ closeAttributedBorrowLimitUsd: number;
310
+ interestRate: {
311
+ id: string;
312
+ utilPercent: BigNumber;
313
+ aprPercent: BigNumber;
314
+ }[];
315
+ };
316
+ $typeName: string;
317
+ id: string;
318
+ arrayIndex: bigint;
319
+ coinType: string;
320
+ mintDecimals: number;
321
+ priceIdentifier: string;
322
+ price: BigNumber;
323
+ smoothedPrice: BigNumber;
324
+ minPrice: BigNumber;
325
+ maxPrice: BigNumber;
326
+ priceLastUpdateTimestampS: bigint;
327
+ availableAmount: BigNumber;
328
+ ctokenSupply: BigNumber;
329
+ borrowedAmount: BigNumber;
330
+ cumulativeBorrowRate: BigNumber;
331
+ interestLastUpdateTimestampS: bigint;
332
+ unclaimedSpreadFees: BigNumber;
333
+ attributedBorrowValue: BigNumber;
334
+ depositsPoolRewardManager: {
335
+ $typeName: string;
336
+ id: string;
337
+ totalShares: bigint;
338
+ poolRewards: {
339
+ $typeName: string;
340
+ id: string;
341
+ poolRewardManagerId: string;
342
+ coinType: string;
343
+ startTimeMs: number;
344
+ endTimeMs: number;
345
+ totalRewards: BigNumber;
346
+ allocatedRewards: BigNumber;
347
+ cumulativeRewardsPerShare: BigNumber;
348
+ numUserRewardManagers: bigint;
349
+ rewardIndex: number;
350
+ symbol: string;
351
+ mintDecimals: number;
352
+ }[];
353
+ lastUpdateTimeMs: bigint;
354
+ };
355
+ borrowsPoolRewardManager: {
356
+ $typeName: string;
357
+ id: string;
358
+ totalShares: bigint;
359
+ poolRewards: {
360
+ $typeName: string;
361
+ id: string;
362
+ poolRewardManagerId: string;
363
+ coinType: string;
364
+ startTimeMs: number;
365
+ endTimeMs: number;
366
+ totalRewards: BigNumber;
367
+ allocatedRewards: BigNumber;
368
+ cumulativeRewardsPerShare: BigNumber;
369
+ numUserRewardManagers: bigint;
370
+ rewardIndex: number;
371
+ symbol: string;
372
+ mintDecimals: number;
373
+ }[];
374
+ lastUpdateTimeMs: bigint;
375
+ };
376
+ availableAmountUsd: BigNumber;
377
+ borrowedAmountUsd: BigNumber;
378
+ depositedAmount: BigNumber;
379
+ depositedAmountUsd: BigNumber;
380
+ cTokenExchangeRate: BigNumber;
381
+ borrowAprPercent: BigNumber;
382
+ depositAprPercent: BigNumber;
383
+ utilizationPercent: BigNumber;
384
+ token: {
385
+ decimals: number;
386
+ description: string;
387
+ iconUrl?: string | null;
388
+ id?: string | null;
389
+ name: string;
390
+ symbol: string;
391
+ coinType: string;
392
+ };
393
+ symbol: string;
394
+ name: string;
395
+ iconUrl: string | null | undefined;
396
+ description: string;
397
+ totalDeposits: BigNumber;
398
+ };
399
+ original: import("../_generated/suilend/obligation/structs").Obligation<string>;
400
+ }[];
401
+ borrows: {
402
+ coinType: string;
403
+ reserveArrayIndex: bigint;
404
+ userRewardManagerIndex: number;
405
+ userRewardManager: import("../_generated/suilend/liquidity-mining/structs").UserRewardManager;
406
+ borrowedAmount: BigNumber;
407
+ borrowedAmountUsd: BigNumber;
408
+ reserve: {
409
+ config: {
410
+ $typeName: string;
411
+ openLtvPct: number;
412
+ closeLtvPct: number;
413
+ maxCloseLtvPct: number;
414
+ borrowWeightBps: BigNumber;
415
+ depositLimit: BigNumber;
416
+ borrowLimit: BigNumber;
417
+ liquidationBonusBps: number;
418
+ maxLiquidationBonusBps: number;
419
+ depositLimitUsd: BigNumber;
420
+ borrowLimitUsd: BigNumber;
421
+ borrowFeeBps: number;
422
+ spreadFeeBps: number;
423
+ protocolLiquidationFeeBps: number;
424
+ isolated: boolean;
425
+ openAttributedBorrowLimitUsd: number;
426
+ closeAttributedBorrowLimitUsd: number;
427
+ interestRate: {
428
+ id: string;
429
+ utilPercent: BigNumber;
430
+ aprPercent: BigNumber;
431
+ }[];
432
+ };
433
+ $typeName: string;
434
+ id: string;
435
+ arrayIndex: bigint;
436
+ coinType: string;
437
+ mintDecimals: number;
438
+ priceIdentifier: string;
439
+ price: BigNumber;
440
+ smoothedPrice: BigNumber;
441
+ minPrice: BigNumber;
442
+ maxPrice: BigNumber;
443
+ priceLastUpdateTimestampS: bigint;
444
+ availableAmount: BigNumber;
445
+ ctokenSupply: BigNumber;
446
+ borrowedAmount: BigNumber;
447
+ cumulativeBorrowRate: BigNumber;
448
+ interestLastUpdateTimestampS: bigint;
449
+ unclaimedSpreadFees: BigNumber;
450
+ attributedBorrowValue: BigNumber;
451
+ depositsPoolRewardManager: {
452
+ $typeName: string;
453
+ id: string;
454
+ totalShares: bigint;
455
+ poolRewards: {
456
+ $typeName: string;
457
+ id: string;
458
+ poolRewardManagerId: string;
459
+ coinType: string;
460
+ startTimeMs: number;
461
+ endTimeMs: number;
462
+ totalRewards: BigNumber;
463
+ allocatedRewards: BigNumber;
464
+ cumulativeRewardsPerShare: BigNumber;
465
+ numUserRewardManagers: bigint;
466
+ rewardIndex: number;
467
+ symbol: string;
468
+ mintDecimals: number;
469
+ }[];
470
+ lastUpdateTimeMs: bigint;
471
+ };
472
+ borrowsPoolRewardManager: {
473
+ $typeName: string;
474
+ id: string;
475
+ totalShares: bigint;
476
+ poolRewards: {
477
+ $typeName: string;
478
+ id: string;
479
+ poolRewardManagerId: string;
480
+ coinType: string;
481
+ startTimeMs: number;
482
+ endTimeMs: number;
483
+ totalRewards: BigNumber;
484
+ allocatedRewards: BigNumber;
485
+ cumulativeRewardsPerShare: BigNumber;
486
+ numUserRewardManagers: bigint;
487
+ rewardIndex: number;
488
+ symbol: string;
489
+ mintDecimals: number;
490
+ }[];
491
+ lastUpdateTimeMs: bigint;
492
+ };
493
+ availableAmountUsd: BigNumber;
494
+ borrowedAmountUsd: BigNumber;
495
+ depositedAmount: BigNumber;
496
+ depositedAmountUsd: BigNumber;
497
+ cTokenExchangeRate: BigNumber;
498
+ borrowAprPercent: BigNumber;
499
+ depositAprPercent: BigNumber;
500
+ utilizationPercent: BigNumber;
501
+ token: {
502
+ decimals: number;
503
+ description: string;
504
+ iconUrl?: string | null;
505
+ id?: string | null;
506
+ name: string;
507
+ symbol: string;
508
+ coinType: string;
509
+ };
510
+ symbol: string;
511
+ name: string;
512
+ iconUrl: string | null | undefined;
513
+ description: string;
514
+ totalDeposits: BigNumber;
515
+ };
516
+ original: import("../_generated/suilend/obligation/structs").Obligation<string>;
517
+ }[];
518
+ weightedConservativeBorrowUtilizationPercent: BigNumber;
519
+ original: import("../_generated/suilend/obligation/structs").Obligation<string>;
520
+ totalSupplyUsd: BigNumber;
521
+ totalBorrowUsd: BigNumber;
522
+ totalWeightedBorrowUsd: BigNumber;
523
+ maxPriceTotalWeightedBorrowUsd: BigNumber;
524
+ borrowLimit: BigNumber;
525
+ minPriceBorrowLimit: BigNumber;
526
+ }[];
268
527
  obligationOwnerCaps: import("../_generated/suilend/lending-market/structs").ObligationOwnerCap<string>[];
269
528
  obligations: {
270
529
  id: string;
package/lib/initialize.js CHANGED
@@ -54,6 +54,7 @@ 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 strategyOwnerCap_1 = require("./strategyOwnerCap");
57
58
  exports.RESERVES_CUSTOM_ORDER = [
58
59
  // MAIN ASSETS
59
60
  sui_fe_1.NORMALIZED_sSUI_COINTYPE,
@@ -82,6 +83,7 @@ exports.RESERVES_CUSTOM_ORDER = [
82
83
  sui_fe_1.NORMALIZED_WAL_COINTYPE,
83
84
  // ISOLATED ASSETS
84
85
  sui_fe_1.NORMALIZED_SEND_COINTYPE,
86
+ sui_fe_1.NORMALIZED_IKA_COINTYPE,
85
87
  sui_fe_1.NORMALIZED_HAEDAL_COINTYPE,
86
88
  sui_fe_1.NORMALIZED_BLUE_COINTYPE,
87
89
  sui_fe_1.NORMALIZED_NS_COINTYPE,
@@ -228,12 +230,50 @@ const initializeSuilendRewards = (reserveMap, activeRewardCoinTypes) => __awaite
228
230
  exports.initializeSuilendRewards = initializeSuilendRewards;
229
231
  const initializeObligations = (suiClient, suilendClient, refreshedRawReserves, reserveMap, address) => __awaiter(void 0, void 0, void 0, function* () {
230
232
  if (!address)
231
- return { obligationOwnerCaps: [], obligations: [] };
232
- const obligationOwnerCaps = yield client_1.SuilendClient.getObligationOwnerCaps(address, suilendClient.lendingMarket.$typeArgs, suiClient);
233
- const obligations = (yield Promise.all(obligationOwnerCaps.map((ownerCap) => client_1.SuilendClient.getObligation(ownerCap.obligationId, suilendClient.lendingMarket.$typeArgs, suiClient))))
233
+ return {
234
+ strategyOwnerCaps: [],
235
+ strategyObligations: [],
236
+ obligationOwnerCaps: [],
237
+ obligations: [],
238
+ };
239
+ const [strategyOwnerCaps, obligationOwnerCaps] = yield Promise.all([
240
+ (() => __awaiter(void 0, void 0, void 0, function* () {
241
+ const objects = yield (0, sui_fe_1.getAllOwnedObjects)(suiClient, address, {
242
+ StructType: `${strategyOwnerCap_1.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::StrategyOwnerCap<${suilendClient.lendingMarket.$typeArgs[0]}>`,
243
+ });
244
+ return objects.map((obj) => {
245
+ var _a;
246
+ const fields = ((_a = obj.data) === null || _a === void 0 ? void 0 : _a.content).fields;
247
+ const id = fields.id.id;
248
+ const strategyType = fields.strategy_type;
249
+ const obligationOwnerCapId = fields.inner_cap.fields.id.id;
250
+ const obligationId = fields.inner_cap.fields.obligation_id;
251
+ const result = {
252
+ id,
253
+ strategyType,
254
+ obligationOwnerCapId,
255
+ obligationId,
256
+ };
257
+ return result;
258
+ });
259
+ }))(),
260
+ client_1.SuilendClient.getObligationOwnerCaps(address, suilendClient.lendingMarket.$typeArgs, suiClient),
261
+ ]);
262
+ const obligations = (yield Promise.all([
263
+ ...strategyOwnerCaps.map((soc) => soc.obligationId),
264
+ ...obligationOwnerCaps.map((ownerCap) => ownerCap.obligationId),
265
+ ].map((obligationId) => client_1.SuilendClient.getObligation(obligationId, suilendClient.lendingMarket.$typeArgs, suiClient))))
234
266
  .map((rawObligation) => simulate.refreshObligation(rawObligation, refreshedRawReserves))
235
267
  .map((refreshedObligation) => (0, parsers_1.parseObligation)(refreshedObligation, reserveMap))
236
268
  .sort((a, b) => +b.netValueUsd.minus(a.netValueUsd));
237
- return { obligationOwnerCaps, obligations };
269
+ // Divide into strategy and non-strategy
270
+ const strategyObligations = obligations.filter((o) => strategyOwnerCaps.some((soc) => soc.obligationId === o.id));
271
+ const nonStrategyObligations = obligations.filter((o) => !strategyObligations.some((so) => so.id === o.id));
272
+ return {
273
+ strategyOwnerCaps,
274
+ strategyObligations,
275
+ obligationOwnerCaps,
276
+ obligations: nonStrategyObligations,
277
+ };
238
278
  });
239
279
  exports.initializeObligations = initializeObligations;
@@ -51,5 +51,5 @@ export declare const getDedupedPerDayRewards: (filteredRewards: RewardSummary[])
51
51
  export declare const getRewardsAprPercent: (side: Side, filteredRewards: RewardSummary[]) => BigNumber;
52
52
  export declare const getStakingYieldAprPercent: (side: Side, coinType: string, lstAprPercentMap: Record<string, BigNumber>) => BigNumber | undefined;
53
53
  export declare const getTotalAprPercent: (side: Side, aprPercent: BigNumber, filteredRewards: RewardSummary[], stakingYieldAprPercent?: BigNumber) => BigNumber;
54
- export declare const getNetAprPercent: (obligation: ParsedObligation, rewardMap: RewardMap, lstAprPercentMap: Record<string, BigNumber>) => BigNumber;
54
+ export declare const getNetAprPercent: (obligation: ParsedObligation, rewardMap: RewardMap, lstAprPercentMap: Record<string, BigNumber>, noShares?: boolean) => BigNumber;
55
55
  export {};
@@ -151,12 +151,14 @@ const getTotalAprPercent = (side, aprPercent, filteredRewards, stakingYieldAprPe
151
151
  .plus((0, exports.getRewardsAprPercent)(side, filteredRewards))
152
152
  .plus(stakingYieldAprPercent !== null && stakingYieldAprPercent !== void 0 ? stakingYieldAprPercent : 0);
153
153
  exports.getTotalAprPercent = getTotalAprPercent;
154
- const getNetAprPercent = (obligation, rewardMap, lstAprPercentMap) => {
154
+ const getNetAprPercent = (obligation, rewardMap, lstAprPercentMap, noShares) => {
155
155
  const weightedDepositedAmountUsd_aprPercent = obligation.deposits.reduce((acc, deposit) => {
156
156
  var _a;
157
157
  const weightedDepositedAmountUsd_baseAprPercent = deposit.reserve.depositAprPercent.times(deposit.depositedAmountUsd);
158
158
  const weightedDepositedAmountUsd_stakingYieldAprPercent = new bignumber_js_1.default((_a = (0, exports.getStakingYieldAprPercent)(types_1.Side.DEPOSIT, deposit.reserve.coinType, lstAprPercentMap)) !== null && _a !== void 0 ? _a : 0).times(deposit.depositedAmountUsd);
159
- const weightedDepositedAmountUsd_rewardsAprPercent = (0, exports.getRewardsAprPercent)(types_1.Side.DEPOSIT, (0, exports.getFilteredRewards)(rewardMap[deposit.reserve.coinType].deposit)).times(getDepositShareUsd(deposit.reserve, new bignumber_js_1.default(deposit.userRewardManager.share.toString())));
159
+ const weightedDepositedAmountUsd_rewardsAprPercent = (0, exports.getRewardsAprPercent)(types_1.Side.DEPOSIT, (0, exports.getFilteredRewards)(rewardMap[deposit.reserve.coinType].deposit)).times(!noShares
160
+ ? getDepositShareUsd(deposit.reserve, new bignumber_js_1.default(deposit.userRewardManager.share.toString()))
161
+ : deposit.depositedAmountUsd);
160
162
  return acc
161
163
  .plus(weightedDepositedAmountUsd_baseAprPercent)
162
164
  .plus(weightedDepositedAmountUsd_stakingYieldAprPercent)
@@ -164,7 +166,9 @@ const getNetAprPercent = (obligation, rewardMap, lstAprPercentMap) => {
164
166
  }, new bignumber_js_1.default(0));
165
167
  const weightedBorrowedAmountUsd_aprPercent = obligation.borrows.reduce((acc, borrow) => {
166
168
  const weightedBorrowedAmountUsd_baseAprPercent = borrow.reserve.borrowAprPercent.times(borrow.borrowedAmountUsd);
167
- const weightedBorrowedAmountUsd_rewardsAprPercent = (0, exports.getRewardsAprPercent)(types_1.Side.BORROW, (0, exports.getFilteredRewards)(rewardMap[borrow.reserve.coinType].borrow)).times(getBorrowShareUsd(borrow.reserve, new bignumber_js_1.default(borrow.userRewardManager.share.toString())));
169
+ const weightedBorrowedAmountUsd_rewardsAprPercent = (0, exports.getRewardsAprPercent)(types_1.Side.BORROW, (0, exports.getFilteredRewards)(rewardMap[borrow.reserve.coinType].borrow)).times(!noShares
170
+ ? getBorrowShareUsd(borrow.reserve, new bignumber_js_1.default(borrow.userRewardManager.share.toString()))
171
+ : borrow.borrowedAmountUsd);
168
172
  return acc
169
173
  .plus(weightedBorrowedAmountUsd_baseAprPercent)
170
174
  .plus(weightedBorrowedAmountUsd_rewardsAprPercent);
@@ -0,0 +1,12 @@
1
+ import { Transaction, TransactionObjectInput, TransactionResult } from "@mysten/sui/transactions";
2
+ import { StrategyOwnerCap } from "./types";
3
+ export declare const STRATEGY_WRAPPER_PACKAGE_ID = "0x2001629d6d87322ab0bd965a5d539acd318069ad589b644b6eaf6c50c606e99c";
4
+ export declare const STRATEGY_SUI_LOOPING_SSUI = 1;
5
+ export declare const strategyDeposit: (coin: TransactionObjectInput, coinType: string, strategyOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, transaction: Transaction) => TransactionResult;
6
+ export declare const strategyBorrow: (coinType: string, strategyOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, value: bigint, transaction: Transaction) => TransactionResult;
7
+ export declare const strategyWithdraw: (coinType: string, strategyOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, value: bigint, transaction: Transaction) => TransactionResult;
8
+ export declare const createStrategyOwnerCapIfNoneExists: (transaction: Transaction, strategyOwnerCap?: StrategyOwnerCap) => {
9
+ strategyOwnerCapId: string | TransactionResult;
10
+ didCreate: boolean;
11
+ };
12
+ export declare const sendStrategyOwnerCapToUser: (strategyOwnerCapId: string | TransactionResult, address: string, transaction: Transaction) => void;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sendStrategyOwnerCapToUser = exports.createStrategyOwnerCapIfNoneExists = exports.strategyWithdraw = exports.strategyBorrow = exports.strategyDeposit = exports.STRATEGY_SUI_LOOPING_SSUI = exports.STRATEGY_WRAPPER_PACKAGE_ID = void 0;
4
+ const utils_1 = require("@mysten/sui/utils");
5
+ const sui_fe_1 = require("@suilend/sui-fe");
6
+ const client_1 = require("../client");
7
+ exports.STRATEGY_WRAPPER_PACKAGE_ID = "0x2001629d6d87322ab0bd965a5d539acd318069ad589b644b6eaf6c50c606e99c";
8
+ exports.STRATEGY_SUI_LOOPING_SSUI = 1;
9
+ const strategyDeposit = (coin, coinType, strategyOwnerCap, reserveArrayIndex, transaction) => transaction.moveCall({
10
+ target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::deposit_liquidity_and_deposit_into_obligation`,
11
+ typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
12
+ arguments: [
13
+ transaction.object(strategyOwnerCap),
14
+ transaction.object(client_1.LENDING_MARKET_ID),
15
+ transaction.pure.u64(reserveArrayIndex),
16
+ transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
17
+ transaction.object(coin),
18
+ ],
19
+ });
20
+ exports.strategyDeposit = strategyDeposit;
21
+ const strategyBorrow = (coinType, strategyOwnerCap, reserveArrayIndex, value, transaction) => (0, sui_fe_1.isSui)(coinType)
22
+ ? transaction.moveCall({
23
+ target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::borrow_sui_from_obligation`,
24
+ typeArguments: [client_1.LENDING_MARKET_TYPE],
25
+ arguments: [
26
+ transaction.object(strategyOwnerCap),
27
+ transaction.object(client_1.LENDING_MARKET_ID),
28
+ transaction.pure.u64(reserveArrayIndex),
29
+ transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
30
+ transaction.pure.u64(value),
31
+ transaction.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID),
32
+ ],
33
+ })
34
+ : transaction.moveCall({
35
+ target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::borrow_from_obligation`,
36
+ typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
37
+ arguments: [
38
+ transaction.object(strategyOwnerCap),
39
+ transaction.object(client_1.LENDING_MARKET_ID),
40
+ transaction.pure.u64(reserveArrayIndex),
41
+ transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
42
+ transaction.pure.u64(value),
43
+ ],
44
+ });
45
+ exports.strategyBorrow = strategyBorrow;
46
+ const strategyWithdraw = (coinType, strategyOwnerCap, reserveArrayIndex, value, transaction) => transaction.moveCall({
47
+ target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::withdraw_from_obligation_and_redeem`,
48
+ typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
49
+ arguments: [
50
+ transaction.object(strategyOwnerCap),
51
+ transaction.object(client_1.LENDING_MARKET_ID),
52
+ transaction.pure.u64(reserveArrayIndex),
53
+ transaction.object(utils_1.SUI_CLOCK_OBJECT_ID),
54
+ transaction.pure.u64(value),
55
+ ],
56
+ });
57
+ exports.strategyWithdraw = strategyWithdraw;
58
+ const createStrategyOwnerCapIfNoneExists = (transaction, strategyOwnerCap) => {
59
+ let strategyOwnerCapId;
60
+ let didCreate = false;
61
+ if (strategyOwnerCap)
62
+ strategyOwnerCapId = strategyOwnerCap.id;
63
+ else {
64
+ strategyOwnerCapId = transaction.moveCall({
65
+ target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::create_strategy_owner_cap`,
66
+ typeArguments: [client_1.LENDING_MARKET_TYPE],
67
+ arguments: [
68
+ transaction.object(client_1.LENDING_MARKET_ID),
69
+ transaction.pure.u8(exports.STRATEGY_SUI_LOOPING_SSUI),
70
+ ],
71
+ });
72
+ didCreate = true;
73
+ }
74
+ return { strategyOwnerCapId, didCreate };
75
+ };
76
+ exports.createStrategyOwnerCapIfNoneExists = createStrategyOwnerCapIfNoneExists;
77
+ const sendStrategyOwnerCapToUser = (strategyOwnerCapId, address, transaction) => {
78
+ transaction.transferObjects([strategyOwnerCapId], transaction.pure.address(address));
79
+ };
80
+ exports.sendStrategyOwnerCapToUser = sendStrategyOwnerCapToUser;
package/lib/types.d.ts CHANGED
@@ -198,3 +198,9 @@ export type ApiObligationDataEvent = {
198
198
  */
199
199
  borrowsJson: string;
200
200
  };
201
+ export type StrategyOwnerCap = {
202
+ id: string;
203
+ strategyType: number;
204
+ obligationOwnerCapId: string;
205
+ obligationId: string;
206
+ };
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sdk","version":"1.1.73","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","./swap":"./swap/index.js","./swap/okxDex":"./swap/okxDex.js","./swap/quote":"./swap/quote.js","./swap/transaction":"./swap/transaction.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/suilend/suilend-fe-public.git"},"bugs":{"url":"https://github.com/suilend/suilend-fe-public/issues"},"dependencies":{"@7kprotocol/sdk-ts":"^3.2.0","@cetusprotocol/aggregator-sdk":"^0.14.1","@flowx-finance/sdk":"^1.11.2","@pythnetwork/pyth-sui-js":"^2.1.0","aftermath-ts-sdk":"^1.3.13","bignumber.js":"^9.1.2","bn.js":"^5.2.2","crypto-js":"^4.2.0","p-limit":"3.1.0","uuid":"^11.0.3"},"devDependencies":{"ts-node":"^10.9.2"},"peerDependencies":{"@mysten/bcs":"1.6.0","@mysten/sui":"1.28.2","@suilend/sui-fe":"^0.3.16"}}
1
+ {"name":"@suilend/sdk","version":"1.1.74","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/strategyOwnerCap":"./lib/strategyOwnerCap.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","./swap":"./swap/index.js","./swap/okxDex":"./swap/okxDex.js","./swap/quote":"./swap/quote.js","./swap/transaction":"./swap/transaction.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/suilend/suilend-fe-public.git"},"bugs":{"url":"https://github.com/suilend/suilend-fe-public/issues"},"dependencies":{"@7kprotocol/sdk-ts":"^3.2.0","@cetusprotocol/aggregator-sdk":"^0.14.1","@flowx-finance/sdk":"^1.11.2","@pythnetwork/pyth-sui-js":"^2.2.0","aftermath-ts-sdk":"^1.3.13","bignumber.js":"^9.1.2","bn.js":"^5.2.2","crypto-js":"^4.2.0","p-limit":"3.1.0","uuid":"^11.0.3"},"devDependencies":{"ts-node":"^10.9.2"},"peerDependencies":{"@mysten/bcs":"1.6.0","@mysten/sui":"1.28.2","@suilend/sui-fe":"^0.3.20"}}