@suilend/sdk 1.1.77 → 1.1.78

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/lib/initialize.js CHANGED
@@ -245,7 +245,7 @@ const initializeObligations = (suiClient, suilendClient, refreshedRawReserves, r
245
245
  if (suilendClient.lendingMarket.id !== client_1.LENDING_MARKET_ID)
246
246
  return []; // Only main lending market has strategy owner caps
247
247
  const objects = yield (0, sui_fe_1.getAllOwnedObjects)(suiClient, address, {
248
- StructType: `${strategyOwnerCap_1.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::StrategyOwnerCap<${suilendClient.lendingMarket.$typeArgs[0]}>`,
248
+ StructType: `${strategyOwnerCap_1.STRATEGY_WRAPPER_PACKAGE_ID_V1}::strategy_wrapper::StrategyOwnerCap<${suilendClient.lendingMarket.$typeArgs[0]}>`,
249
249
  });
250
250
  return objects.map((obj) => {
251
251
  var _a;
@@ -1,8 +1,9 @@
1
1
  import { AggregatorClient as CetusSdk } from "@cetusprotocol/aggregator-sdk";
2
2
  import { Transaction, TransactionObjectInput, TransactionResult } from "@mysten/sui/transactions";
3
+ import BigNumber from "bignumber.js";
3
4
  import { ParsedObligation, ParsedReserve } from "../parsers";
4
5
  import { RewardsMap, StrategyOwnerCap } from "./types";
5
- export declare const STRATEGY_WRAPPER_PACKAGE_ID = "0xba97dc73a07638d03d77ad2161484eb21db577edc9cadcd7035fef4b4f2f6fa1";
6
+ export declare const STRATEGY_WRAPPER_PACKAGE_ID_V1 = "0xba97dc73a07638d03d77ad2161484eb21db577edc9cadcd7035fef4b4f2f6fa1";
6
7
  export declare enum StrategyType {
7
8
  sSUI_SUI_LOOPING = "1",
8
9
  stratSUI_SUI_LOOPING = "2",
@@ -16,17 +17,19 @@ export declare const STRATEGY_TYPE_INFO_MAP: Record<StrategyType, {
16
17
  tooltip: string;
17
18
  type: string;
18
19
  };
19
- defaultOpenCloseCoinType: string;
20
- openCloseCoinTypeOptions: string[];
21
- depositCoinTypes: string[];
20
+ depositBaseCoinType?: string;
21
+ depositLstCoinType: string;
22
22
  borrowCoinType: string;
23
- lstCoinType: string;
23
+ currencyCoinTypes: string[];
24
+ defaultCurrencyCoinType: string;
24
25
  }>;
25
26
  export declare const strategyDeposit: (coin: TransactionObjectInput, coinType: string, strategyOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, transaction: Transaction) => TransactionResult;
26
27
  export declare const strategyBorrow: (coinType: string, strategyOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, value: bigint, transaction: Transaction) => TransactionResult;
27
28
  export declare const strategyWithdraw: (coinType: string, strategyOwnerCap: TransactionObjectInput, reserveArrayIndex: bigint, value: bigint, transaction: Transaction) => TransactionResult;
28
- export declare const strategyClaimRewardsAndSwap: (address: string, cetusSdk: CetusSdk, cetusPartnerId: string, rewardsMap: RewardsMap, lstReserve: ParsedReserve, strategyOwnerCap: TransactionObjectInput, isDepositing: boolean, transaction: Transaction) => Promise<void>;
29
- export declare const strategySwapNonLstDepositsForLst: (cetusSdk: CetusSdk, cetusPartnerId: string, obligation: ParsedObligation, lstReserve: ParsedReserve, strategyOwnerCap: TransactionObjectInput, transaction: Transaction) => Promise<void>;
29
+ export declare const strategyClaimRewardsAndSwapForCoinType: (address: string, cetusSdk: CetusSdk, cetusPartnerId: string, rewardsMap: RewardsMap, depositReserve: ParsedReserve, strategyOwnerCap: TransactionObjectInput, isDepositing: boolean, transaction: Transaction) => Promise<void>;
30
+ export declare const strategySwapSomeDepositsForCoinType: (strategyType: StrategyType, cetusSdk: CetusSdk, cetusPartnerId: string, obligation: ParsedObligation, noSwapCoinTypes: string[], // coinTypes to not swap for depositReserve.coinType
31
+ swapPercent: BigNumber, // percent of deposit to swap for depositReserve.coinType (0-100)
32
+ depositReserve: ParsedReserve, strategyOwnerCap: TransactionObjectInput, transaction: Transaction) => Promise<void>;
30
33
  export declare const createStrategyOwnerCapIfNoneExists: (strategyType: StrategyType, strategyOwnerCap: StrategyOwnerCap | undefined, transaction: Transaction) => {
31
34
  strategyOwnerCapId: string | TransactionResult;
32
35
  didCreate: boolean;
@@ -12,14 +12,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.sendStrategyOwnerCapToUser = exports.createStrategyOwnerCapIfNoneExists = exports.strategySwapNonLstDepositsForLst = exports.strategyClaimRewardsAndSwap = exports.strategyWithdraw = exports.strategyBorrow = exports.strategyDeposit = exports.STRATEGY_TYPE_INFO_MAP = exports.StrategyType = exports.STRATEGY_WRAPPER_PACKAGE_ID = void 0;
15
+ exports.sendStrategyOwnerCapToUser = exports.createStrategyOwnerCapIfNoneExists = exports.strategySwapSomeDepositsForCoinType = exports.strategyClaimRewardsAndSwapForCoinType = exports.strategyWithdraw = exports.strategyBorrow = exports.strategyDeposit = exports.STRATEGY_TYPE_INFO_MAP = exports.StrategyType = exports.STRATEGY_WRAPPER_PACKAGE_ID_V1 = void 0;
16
16
  const utils_1 = require("@mysten/sui/utils");
17
- const bignumber_js_1 = require("bignumber.js");
17
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
18
18
  const bn_js_1 = __importDefault(require("bn.js"));
19
19
  const sui_fe_1 = require("@suilend/sui-fe");
20
20
  const client_1 = require("../client");
21
21
  const types_1 = require("./types");
22
- exports.STRATEGY_WRAPPER_PACKAGE_ID = "0xba97dc73a07638d03d77ad2161484eb21db577edc9cadcd7035fef4b4f2f6fa1";
22
+ exports.STRATEGY_WRAPPER_PACKAGE_ID_V1 = "0xba97dc73a07638d03d77ad2161484eb21db577edc9cadcd7035fef4b4f2f6fa1";
23
+ const STRATEGY_WRAPPER_PACKAGE_ID_V5 = "0x2a7798449db0ff2de67a72c71c6de4bcbfc8c1dd570053a1894c73047c7b7338";
23
24
  var StrategyType;
24
25
  (function (StrategyType) {
25
26
  StrategyType["sSUI_SUI_LOOPING"] = "1";
@@ -35,14 +36,11 @@ exports.STRATEGY_TYPE_INFO_MAP = {
35
36
  tooltip: "Sets up a sSUI/SUI Looping strategy by depositing sSUI and borrowing SUI to the desired leverage",
36
37
  type: "Looping",
37
38
  },
38
- defaultOpenCloseCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
39
- openCloseCoinTypeOptions: [
40
- sui_fe_1.NORMALIZED_SUI_COINTYPE,
41
- sui_fe_1.NORMALIZED_sSUI_COINTYPE,
42
- ],
43
- depositCoinTypes: [sui_fe_1.NORMALIZED_sSUI_COINTYPE],
39
+ depositBaseCoinType: undefined,
40
+ depositLstCoinType: sui_fe_1.NORMALIZED_sSUI_COINTYPE,
44
41
  borrowCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
45
- lstCoinType: sui_fe_1.NORMALIZED_sSUI_COINTYPE,
42
+ currencyCoinTypes: [sui_fe_1.NORMALIZED_SUI_COINTYPE, sui_fe_1.NORMALIZED_sSUI_COINTYPE],
43
+ defaultCurrencyCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
46
44
  },
47
45
  [StrategyType.stratSUI_SUI_LOOPING]: {
48
46
  queryParam: "stratSUI-SUI-looping",
@@ -52,32 +50,29 @@ exports.STRATEGY_TYPE_INFO_MAP = {
52
50
  tooltip: "Sets up a stratSUI/SUI Looping strategy by depositing stratSUI and borrowing SUI to the desired leverage",
53
51
  type: "Looping",
54
52
  },
55
- defaultOpenCloseCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
56
- openCloseCoinTypeOptions: [
57
- sui_fe_1.NORMALIZED_SUI_COINTYPE,
58
- sui_fe_1.NORMALIZED_stratSUI_COINTYPE,
59
- ],
60
- depositCoinTypes: [sui_fe_1.NORMALIZED_stratSUI_COINTYPE],
53
+ depositBaseCoinType: undefined,
54
+ depositLstCoinType: sui_fe_1.NORMALIZED_stratSUI_COINTYPE,
61
55
  borrowCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
62
- lstCoinType: sui_fe_1.NORMALIZED_stratSUI_COINTYPE,
56
+ currencyCoinTypes: [sui_fe_1.NORMALIZED_SUI_COINTYPE, sui_fe_1.NORMALIZED_stratSUI_COINTYPE],
57
+ defaultCurrencyCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
63
58
  },
64
59
  [StrategyType.USDC_sSUI_SUI_LOOPING]: {
65
60
  queryParam: "USDC-sSUI-SUI-looping",
66
61
  header: {
67
62
  coinTypes: [sui_fe_1.NORMALIZED_USDC_COINTYPE],
68
- title: "USDC",
63
+ title: "USDC sSUI/SUI",
69
64
  tooltip: "Sets up a USDC sSUI/SUI Looping strategy by depositing USDC and looping sSUI/SUI to the desired leverage",
70
65
  type: "Looping",
71
66
  },
72
- defaultOpenCloseCoinType: sui_fe_1.NORMALIZED_USDC_COINTYPE,
73
- openCloseCoinTypeOptions: [sui_fe_1.NORMALIZED_USDC_COINTYPE],
74
- depositCoinTypes: [sui_fe_1.NORMALIZED_USDC_COINTYPE, sui_fe_1.NORMALIZED_sSUI_COINTYPE],
67
+ depositBaseCoinType: sui_fe_1.NORMALIZED_USDC_COINTYPE,
68
+ depositLstCoinType: sui_fe_1.NORMALIZED_sSUI_COINTYPE,
75
69
  borrowCoinType: sui_fe_1.NORMALIZED_SUI_COINTYPE,
76
- lstCoinType: sui_fe_1.NORMALIZED_sSUI_COINTYPE,
70
+ currencyCoinTypes: [sui_fe_1.NORMALIZED_USDC_COINTYPE],
71
+ defaultCurrencyCoinType: sui_fe_1.NORMALIZED_USDC_COINTYPE,
77
72
  },
78
73
  };
79
74
  const strategyDeposit = (coin, coinType, strategyOwnerCap, reserveArrayIndex, transaction) => transaction.moveCall({
80
- target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::deposit_liquidity_and_deposit_into_obligation`,
75
+ target: `${STRATEGY_WRAPPER_PACKAGE_ID_V5}::strategy_wrapper::deposit_liquidity_and_deposit_into_obligation`,
81
76
  typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
82
77
  arguments: [
83
78
  transaction.object(strategyOwnerCap),
@@ -90,7 +85,7 @@ const strategyDeposit = (coin, coinType, strategyOwnerCap, reserveArrayIndex, tr
90
85
  exports.strategyDeposit = strategyDeposit;
91
86
  const strategyBorrow = (coinType, strategyOwnerCap, reserveArrayIndex, value, transaction) => (0, sui_fe_1.isSui)(coinType)
92
87
  ? transaction.moveCall({
93
- target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::borrow_sui_from_obligation`,
88
+ target: `${STRATEGY_WRAPPER_PACKAGE_ID_V5}::strategy_wrapper::borrow_sui_from_obligation`,
94
89
  typeArguments: [client_1.LENDING_MARKET_TYPE],
95
90
  arguments: [
96
91
  transaction.object(strategyOwnerCap),
@@ -102,7 +97,7 @@ const strategyBorrow = (coinType, strategyOwnerCap, reserveArrayIndex, value, tr
102
97
  ],
103
98
  })
104
99
  : transaction.moveCall({
105
- target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::borrow_from_obligation`,
100
+ target: `${STRATEGY_WRAPPER_PACKAGE_ID_V5}::strategy_wrapper::borrow_from_obligation`,
106
101
  typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
107
102
  arguments: [
108
103
  transaction.object(strategyOwnerCap),
@@ -114,7 +109,7 @@ const strategyBorrow = (coinType, strategyOwnerCap, reserveArrayIndex, value, tr
114
109
  });
115
110
  exports.strategyBorrow = strategyBorrow;
116
111
  const strategyWithdraw = (coinType, strategyOwnerCap, reserveArrayIndex, value, transaction) => transaction.moveCall({
117
- target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::withdraw_from_obligation_and_redeem`,
112
+ target: `${STRATEGY_WRAPPER_PACKAGE_ID_V5}::strategy_wrapper::withdraw_from_obligation_and_redeem`,
118
113
  typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
119
114
  arguments: [
120
115
  transaction.object(strategyOwnerCap),
@@ -126,7 +121,7 @@ const strategyWithdraw = (coinType, strategyOwnerCap, reserveArrayIndex, value,
126
121
  });
127
122
  exports.strategyWithdraw = strategyWithdraw;
128
123
  const strategyClaimRewards = (coinType, strategyOwnerCap, reserveArrayIndex, rewardIndex, side, transaction) => transaction.moveCall({
129
- target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::claim_rewards`,
124
+ target: `${STRATEGY_WRAPPER_PACKAGE_ID_V5}::strategy_wrapper::claim_rewards`,
130
125
  typeArguments: [client_1.LENDING_MARKET_TYPE, coinType],
131
126
  arguments: [
132
127
  transaction.object(strategyOwnerCap),
@@ -164,12 +159,12 @@ const strategyClaimRewardsAndMergeCoins = (rewardsMap, strategyOwnerCap, transac
164
159
  }
165
160
  return mergedCoinsMap;
166
161
  };
167
- const strategyClaimRewardsAndSwap = (address, cetusSdk, cetusPartnerId, rewardsMap, lstReserve, strategyOwnerCap, isDepositing, transaction) => __awaiter(void 0, void 0, void 0, function* () {
162
+ const strategyClaimRewardsAndSwapForCoinType = (address, cetusSdk, cetusPartnerId, rewardsMap, depositReserve, strategyOwnerCap, isDepositing, transaction) => __awaiter(void 0, void 0, void 0, function* () {
168
163
  // 1) Claim rewards and merge coins
169
164
  const mergedCoinsMap = strategyClaimRewardsAndMergeCoins(rewardsMap, strategyOwnerCap, transaction);
170
165
  // 2) Prepare
171
- const nonSwappedCoinTypes = Object.keys(mergedCoinsMap).filter((coinType) => coinType === lstReserve.coinType);
172
- const swappedCoinTypes = Object.keys(mergedCoinsMap).filter((coinType) => coinType !== lstReserve.coinType);
166
+ const nonSwappedCoinTypes = Object.keys(mergedCoinsMap).filter((coinType) => coinType === depositReserve.coinType);
167
+ const swappedCoinTypes = Object.keys(mergedCoinsMap).filter((coinType) => coinType !== depositReserve.coinType);
173
168
  let resultCoin = undefined;
174
169
  // 3.1) Non-swapped coins
175
170
  for (const [coinType, coin] of Object.entries(mergedCoinsMap).filter(([coinType]) => nonSwappedCoinTypes.includes(coinType))) {
@@ -188,31 +183,28 @@ const strategyClaimRewardsAndSwap = (address, cetusSdk, cetusPartnerId, rewardsM
188
183
  // Get routes
189
184
  const routers = yield cetusSdk.findRouters({
190
185
  from: coinType,
191
- target: lstReserve.coinType,
186
+ target: depositReserve.coinType,
192
187
  amount: new bn_js_1.default(amount.toString()), // Underestimate (rewards keep accruing)
193
188
  byAmountIn: true,
194
189
  });
195
190
  if (!routers)
196
191
  throw new Error(`No swap quote found for ${coinType}`);
197
- console.log("[strategyClaimRewardsAndSwap] routers", {
192
+ console.log("[strategyClaimRewardsAndSwapForCoinType] routers", {
198
193
  coinType,
199
194
  routers,
200
195
  });
201
196
  return [coinType, { coin, routers }];
202
197
  }))())));
203
- console.log("[strategyClaimRewardsAndSwap] amountsAndSortedQuotesMap", {
204
- amountsAndSortedQuotesMap,
205
- });
198
+ console.log("[strategyClaimRewardsAndSwapForCoinType] amountsAndSortedQuotesMap", { amountsAndSortedQuotesMap });
206
199
  // 3.2.2) Swap
207
200
  for (const [coinType, { coin: coinIn, routers }] of Object.entries(amountsAndSortedQuotesMap)) {
208
- console.log("[strategyClaimRewardsAndSwap] swapping coinType", coinType);
209
- const slippagePercent = 3;
201
+ console.log("[strategyClaimRewardsAndSwapForCoinType] swapping coinType", coinType);
210
202
  let coinOut;
211
203
  try {
212
204
  coinOut = yield cetusSdk.fixableRouterSwapV3({
213
205
  router: routers,
214
206
  inputCoin: coinIn,
215
- slippage: slippagePercent / 100,
207
+ slippage: 3 / 100,
216
208
  txb: transaction,
217
209
  partner: cetusPartnerId,
218
210
  });
@@ -229,21 +221,31 @@ const strategyClaimRewardsAndSwap = (address, cetusSdk, cetusPartnerId, rewardsM
229
221
  if (!resultCoin)
230
222
  throw new Error("No coin to deposit or transfer");
231
223
  if (isDepositing) {
232
- (0, exports.strategyDeposit)(resultCoin, lstReserve.coinType, strategyOwnerCap, lstReserve.arrayIndex, transaction);
224
+ (0, exports.strategyDeposit)(resultCoin, depositReserve.coinType, strategyOwnerCap, depositReserve.arrayIndex, transaction);
233
225
  }
234
226
  else {
235
227
  transaction.transferObjects([resultCoin], transaction.pure.address(address));
236
228
  }
237
229
  });
238
- exports.strategyClaimRewardsAndSwap = strategyClaimRewardsAndSwap;
239
- const strategySwapNonLstDepositsForLst = (cetusSdk, cetusPartnerId, obligation, lstReserve, strategyOwnerCap, transaction) => __awaiter(void 0, void 0, void 0, function* () {
240
- // 1) MAX Withdraw non-LST deposits
241
- const nonLstDeposits = obligation.deposits.filter((deposit) => deposit.coinType !== lstReserve.coinType);
242
- if (nonLstDeposits.length === 0)
230
+ exports.strategyClaimRewardsAndSwapForCoinType = strategyClaimRewardsAndSwapForCoinType;
231
+ const strategySwapSomeDepositsForCoinType = (strategyType, cetusSdk, cetusPartnerId, obligation, noSwapCoinTypes, // coinTypes to not swap for depositReserve.coinType
232
+ swapPercent, // percent of deposit to swap for depositReserve.coinType (0-100)
233
+ depositReserve, strategyOwnerCap, transaction) => __awaiter(void 0, void 0, void 0, function* () {
234
+ // 1) MAX withdraw non-swapCoinTypes deposits
235
+ const swapCoinTypeDeposits = obligation.deposits.filter((deposit) => !noSwapCoinTypes.includes(deposit.coinType));
236
+ if (swapCoinTypeDeposits.length === 0)
243
237
  return;
244
238
  const withdrawnCoinsMap = {};
245
- for (const deposit of nonLstDeposits) {
246
- const [withdrawnCoin] = (0, exports.strategyWithdraw)(deposit.coinType, strategyOwnerCap, deposit.reserve.arrayIndex, BigInt(sui_fe_1.MAX_U64.toString()), transaction);
239
+ for (const deposit of swapCoinTypeDeposits) {
240
+ const [withdrawnCoin] = (0, exports.strategyWithdraw)(deposit.coinType, strategyOwnerCap, deposit.reserve.arrayIndex, swapPercent.eq(100)
241
+ ? BigInt(sui_fe_1.MAX_U64.toString())
242
+ : BigInt(new bignumber_js_1.default(new bignumber_js_1.default(deposit.depositedAmount.times(swapPercent.div(100)))
243
+ .times(10 ** deposit.reserve.token.decimals)
244
+ .integerValue(bignumber_js_1.default.ROUND_DOWN)
245
+ .toString())
246
+ .div(deposit.reserve.cTokenExchangeRate)
247
+ .integerValue(bignumber_js_1.default.ROUND_UP)
248
+ .toString()), transaction);
247
249
  withdrawnCoinsMap[deposit.coinType] = {
248
250
  deposit,
249
251
  coin: withdrawnCoin,
@@ -254,37 +256,34 @@ const strategySwapNonLstDepositsForLst = (cetusSdk, cetusPartnerId, obligation,
254
256
  // 2.1) Get routers
255
257
  const amountsAndSortedQuotesMap = Object.fromEntries(yield Promise.all(Object.entries(withdrawnCoinsMap).map(([coinType, { deposit, coin }]) => (() => __awaiter(void 0, void 0, void 0, function* () {
256
258
  // Get amount
257
- const amount = deposit.depositedAmount
259
+ const amount = new bignumber_js_1.default(deposit.depositedAmount.times(swapPercent.div(100)))
258
260
  .times(10 ** deposit.reserve.token.decimals)
259
- .integerValue(bignumber_js_1.BigNumber.ROUND_DOWN); // Use underestimate (deposits keep accruing if deposit APR >0)
261
+ .integerValue(bignumber_js_1.default.ROUND_DOWN); // Use underestimate (deposits keep accruing if deposit APR >0)
260
262
  // Get routes
261
263
  const routers = yield cetusSdk.findRouters({
262
264
  from: deposit.coinType,
263
- target: lstReserve.coinType,
265
+ target: depositReserve.coinType,
264
266
  amount: new bn_js_1.default(amount.toString()), // Underestimate (deposits keep accruing if deposit APR >0)
265
267
  byAmountIn: true,
266
268
  });
267
269
  if (!routers)
268
270
  throw new Error(`No swap quote found for ${deposit.coinType}`);
269
- console.log("[strategySwapNonLstDepositsForLst] routers", {
271
+ console.log("[strategySwapSomeDepositsForCoinType] routers", {
270
272
  coinType: deposit.coinType,
271
273
  routers,
272
274
  });
273
275
  return [deposit.coinType, { coin, routers }];
274
276
  }))())));
275
- console.log("[strategySwapNonLstDepositsForLst] amountsAndSortedQuotesMap", {
276
- amountsAndSortedQuotesMap,
277
- });
277
+ console.log("[strategySwapSomeDepositsForCoinType] amountsAndSortedQuotesMap", { amountsAndSortedQuotesMap });
278
278
  // 2.2) Swap
279
279
  for (const [coinType, { coin: coinIn, routers }] of Object.entries(amountsAndSortedQuotesMap)) {
280
- console.log("[strategySwapNonLstDepositsForLst] swapping coinType", coinType);
281
- const slippagePercent = 3;
280
+ console.log("[strategySwapSomeDepositsForCoinType] swapping coinType", coinType);
282
281
  let coinOut;
283
282
  try {
284
283
  coinOut = yield cetusSdk.fixableRouterSwapV3({
285
284
  router: routers,
286
285
  inputCoin: coinIn,
287
- slippage: slippagePercent / 100,
286
+ slippage: 3 / 100,
288
287
  txb: transaction,
289
288
  partner: cetusPartnerId,
290
289
  });
@@ -300,10 +299,10 @@ const strategySwapNonLstDepositsForLst = (cetusSdk, cetusPartnerId, obligation,
300
299
  // 3) Deposit
301
300
  if (!resultCoin)
302
301
  throw new Error("No coin to deposit or transfer");
303
- console.log("[strategySwapNonLstDepositsForLst] depositing resultCoin");
304
- (0, exports.strategyDeposit)(resultCoin, lstReserve.coinType, strategyOwnerCap, lstReserve.arrayIndex, transaction);
302
+ console.log("[strategySwapSomeDepositsForCoinType] depositing resultCoin");
303
+ (0, exports.strategyDeposit)(resultCoin, depositReserve.coinType, strategyOwnerCap, depositReserve.arrayIndex, transaction);
305
304
  });
306
- exports.strategySwapNonLstDepositsForLst = strategySwapNonLstDepositsForLst;
305
+ exports.strategySwapSomeDepositsForCoinType = strategySwapSomeDepositsForCoinType;
307
306
  const createStrategyOwnerCapIfNoneExists = (strategyType, strategyOwnerCap, transaction) => {
308
307
  let strategyOwnerCapId;
309
308
  let didCreate = false;
@@ -311,7 +310,7 @@ const createStrategyOwnerCapIfNoneExists = (strategyType, strategyOwnerCap, tran
311
310
  strategyOwnerCapId = strategyOwnerCap.id;
312
311
  else {
313
312
  strategyOwnerCapId = transaction.moveCall({
314
- target: `${exports.STRATEGY_WRAPPER_PACKAGE_ID}::strategy_wrapper::create_strategy_owner_cap`,
313
+ target: `${STRATEGY_WRAPPER_PACKAGE_ID_V5}::strategy_wrapper::create_strategy_owner_cap`,
315
314
  typeArguments: [client_1.LENDING_MARKET_TYPE],
316
315
  arguments: [
317
316
  transaction.object(client_1.LENDING_MARKET_ID),
package/lib/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import BigNumber from "bignumber.js";
1
2
  import { RewardSummary } from "./liquidityMining";
2
3
  import { StrategyType } from "./strategyOwnerCap";
3
4
  export declare enum Side {
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sdk","version":"1.1.77","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/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.4.0","@cetusprotocol/aggregator-sdk":"^1.1.2","@flowx-finance/sdk":"^1.11.3","@pythnetwork/pyth-sui-js":"^2.2.0","aftermath-ts-sdk":"^1.3.14","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":{"@types/bn.js":"^5.2.0","ts-node":"^10.9.2"},"peerDependencies":{"@mysten/bcs":"1.6.0","@mysten/sui":"1.28.2","@suilend/sui-fe":"^0.3.29"}}
1
+ {"name":"@suilend/sdk","version":"1.1.78","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/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.4.0","@cetusprotocol/aggregator-sdk":"^1.1.2","@flowx-finance/sdk":"^1.11.3","@pythnetwork/pyth-sui-js":"^2.2.0","aftermath-ts-sdk":"^1.3.14","bignumber.js":"^9.1.2","bn.js":"^5.2.2","crypto-js":"^4.2.0","lodash":"^4.17.21","p-limit":"3.1.0","uuid":"^11.0.3"},"devDependencies":{"@types/bn.js":"^5.2.0","@types/lodash":"^4.17.20","ts-node":"^10.9.2"},"peerDependencies":{"@mysten/bcs":"1.6.0","@mysten/sui":"1.28.2","@suilend/sui-fe":"^0.3.29"}}
package/swap/quote.js CHANGED
@@ -119,11 +119,11 @@ const getAftermathQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0
119
119
  provider: path.protocolName,
120
120
  in: {
121
121
  coinType: (0, utils_1.normalizeStructTag)(path.coinIn.type),
122
- amount: new bignumber_js_1.default(path.coinIn.amount.toString()).div(10 ** tokenIn.decimals),
122
+ amount: new bignumber_js_1.default(path.coinIn.amount.toString()),
123
123
  },
124
124
  out: {
125
125
  coinType: (0, utils_1.normalizeStructTag)(path.coinOut.type),
126
- amount: new bignumber_js_1.default(path.coinOut.amount.toString()).div(10 ** tokenOut.decimals),
126
+ amount: new bignumber_js_1.default(path.coinOut.amount.toString()),
127
127
  },
128
128
  })),
129
129
  })),
@@ -188,11 +188,11 @@ const getCetusQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
188
188
  provider: path.provider,
189
189
  in: {
190
190
  coinType: (0, utils_1.normalizeStructTag)(path.from),
191
- amount: new bignumber_js_1.default(path.amountIn.toString()).div(10 ** tokenIn.decimals),
191
+ amount: new bignumber_js_1.default(path.amountIn.toString()),
192
192
  },
193
193
  out: {
194
194
  coinType: (0, utils_1.normalizeStructTag)(path.target),
195
- amount: new bignumber_js_1.default(path.amountOut.toString()).div(10 ** tokenOut.decimals),
195
+ amount: new bignumber_js_1.default(path.amountOut.toString()),
196
196
  },
197
197
  })),
198
198
  })),
@@ -212,11 +212,11 @@ const get7kQuote = (tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, vo
212
212
  provider: QuoteProvider._7K,
213
213
  in: {
214
214
  coinType: tokenIn.coinType,
215
- amount: new bignumber_js_1.default(quote.swapAmount),
215
+ amount: new bignumber_js_1.default(quote.swapAmountWithDecimal).div(10 ** tokenIn.decimals),
216
216
  },
217
217
  out: {
218
218
  coinType: tokenOut.coinType,
219
- amount: new bignumber_js_1.default(quote.returnAmount),
219
+ amount: new bignumber_js_1.default(quote.returnAmountWithDecimal).div(10 ** tokenOut.decimals),
220
220
  },
221
221
  routes: ((_a = quote.routes) !== null && _a !== void 0 ? _a : []).map((route, routeIndex) => ({
222
222
  percent: new bignumber_js_1.default(route.tokenInAmount)
@@ -229,11 +229,15 @@ const get7kQuote = (tokenIn, tokenOut, amountIn) => __awaiter(void 0, void 0, vo
229
229
  provider: hop.pool.type,
230
230
  in: {
231
231
  coinType: (0, utils_1.normalizeStructTag)(hop.tokenIn),
232
- amount: new bignumber_js_1.default(hop.tokenInAmount),
232
+ amount: new bignumber_js_1.default(hop.tokenInAmount).times(10 **
233
+ hop.pool.allTokens.find((t) => (0, utils_1.normalizeStructTag)(t.address) ===
234
+ (0, utils_1.normalizeStructTag)(hop.tokenIn)).decimal),
233
235
  },
234
236
  out: {
235
237
  coinType: (0, utils_1.normalizeStructTag)(hop.tokenOut),
236
- amount: new bignumber_js_1.default(hop.tokenOutAmount),
238
+ amount: new bignumber_js_1.default(hop.tokenOutAmount).times(10 **
239
+ hop.pool.allTokens.find((t) => (0, utils_1.normalizeStructTag)(t.address) ===
240
+ (0, utils_1.normalizeStructTag)(hop.tokenOut)).decimal),
237
241
  },
238
242
  })),
239
243
  })),
@@ -270,11 +274,11 @@ const getFlowXQuote = (sdk, tokenIn, tokenOut, amountIn) => __awaiter(void 0, vo
270
274
  provider: hop.protocol(),
271
275
  in: {
272
276
  coinType: (0, utils_1.normalizeStructTag)(hop.input.coinType),
273
- amount: new bignumber_js_1.default(hop.amountIn.toString()).div(10 ** tokenIn.decimals),
277
+ amount: new bignumber_js_1.default(hop.amountIn.toString()),
274
278
  },
275
279
  out: {
276
280
  coinType: (0, utils_1.normalizeStructTag)(hop.output.coinType),
277
- amount: new bignumber_js_1.default(hop.amountOut.toString()).div(10 ** tokenOut.decimals),
281
+ amount: new bignumber_js_1.default(hop.amountOut.toString()),
278
282
  },
279
283
  })),
280
284
  })),