@t2000/sdk 0.16.15 → 0.16.17

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.
@@ -1,4 +1,4 @@
1
- export { w as AdapterCapability, x as AdapterPositions, y as AdapterTxResult, C as CetusAdapter, K as HealthInfo, L as LendingAdapter, s as LendingRates, N as NaviAdapter, O as PerpsAdapter, X as ProtocolDescriptor, Y as ProtocolRegistry, $ as SuilendAdapter, d as SwapAdapter, a0 as SwapQuote, a3 as allDescriptors, a4 as cetusDescriptor, a7 as naviDescriptor, aa as sentinelDescriptor, ad as suilendDescriptor } from '../index-BOkO4S7r.cjs';
1
+ export { w as AdapterCapability, x as AdapterPositions, y as AdapterTxResult, C as CetusAdapter, K as HealthInfo, L as LendingAdapter, s as LendingRates, N as NaviAdapter, O as PerpsAdapter, X as ProtocolDescriptor, Y as ProtocolRegistry, $ as SuilendAdapter, d as SwapAdapter, a0 as SwapQuote, a3 as allDescriptors, a4 as cetusDescriptor, a7 as naviDescriptor, aa as sentinelDescriptor, ad as suilendDescriptor } from '../index-BRjfwac2.cjs';
2
2
  import '@mysten/sui/transactions';
3
3
  import '@mysten/sui/jsonRpc';
4
4
  import '@mysten/sui/keypairs/ed25519';
@@ -1,4 +1,4 @@
1
- export { w as AdapterCapability, x as AdapterPositions, y as AdapterTxResult, C as CetusAdapter, K as HealthInfo, L as LendingAdapter, s as LendingRates, N as NaviAdapter, O as PerpsAdapter, X as ProtocolDescriptor, Y as ProtocolRegistry, $ as SuilendAdapter, d as SwapAdapter, a0 as SwapQuote, a3 as allDescriptors, a4 as cetusDescriptor, a7 as naviDescriptor, aa as sentinelDescriptor, ad as suilendDescriptor } from '../index-BOkO4S7r.js';
1
+ export { w as AdapterCapability, x as AdapterPositions, y as AdapterTxResult, C as CetusAdapter, K as HealthInfo, L as LendingAdapter, s as LendingRates, N as NaviAdapter, O as PerpsAdapter, X as ProtocolDescriptor, Y as ProtocolRegistry, $ as SuilendAdapter, d as SwapAdapter, a0 as SwapQuote, a3 as allDescriptors, a4 as cetusDescriptor, a7 as naviDescriptor, aa as sentinelDescriptor, ad as suilendDescriptor } from '../index-BRjfwac2.js';
2
2
  import '@mysten/sui/transactions';
3
3
  import '@mysten/sui/jsonRpc';
4
4
  import '@mysten/sui/keypairs/ed25519';
@@ -1133,6 +1133,7 @@ var CetusAdapter = class {
1133
1133
  var WAD = 1e18;
1134
1134
  var MIN_HEALTH_FACTOR2 = 1.5;
1135
1135
  var CLOCK2 = "0x6";
1136
+ var SUI_SYSTEM_STATE2 = "0x5";
1136
1137
  var LENDING_MARKET_ID = "0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1";
1137
1138
  var LENDING_MARKET_TYPE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL";
1138
1139
  var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
@@ -1148,6 +1149,9 @@ var descriptor3 = {
1148
1149
  "lending_market::create_obligation": "save",
1149
1150
  "lending_market::withdraw_ctokens": "withdraw",
1150
1151
  "lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
1152
+ "lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
1153
+ "lending_market::fulfill_liquidity_request": "withdraw",
1154
+ "lending_market::unstake_sui_from_staker": "withdraw",
1151
1155
  "lending_market::borrow": "borrow",
1152
1156
  "lending_market::repay": "repay"
1153
1157
  }
@@ -1492,7 +1496,9 @@ var SuilendAdapter = class {
1492
1496
  const deposited = dep ? dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals : 0;
1493
1497
  const effectiveAmount = Math.min(amount, deposited);
1494
1498
  if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on Suilend`);
1495
- const ctokenAmount = dep && effectiveAmount >= deposited * 0.999 ? dep.ctokenAmount : Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
1499
+ const U64_MAX = "18446744073709551615";
1500
+ const isFullWithdraw = dep && effectiveAmount >= deposited * 0.999;
1501
+ const withdrawArg = isFullWithdraw ? U64_MAX : String(Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio));
1496
1502
  const tx = new Transaction();
1497
1503
  tx.setSender(address);
1498
1504
  const [ctokens] = tx.moveCall({
@@ -1503,25 +1509,10 @@ var SuilendAdapter = class {
1503
1509
  tx.pure.u64(reserve.arrayIndex),
1504
1510
  tx.object(caps[0].id),
1505
1511
  tx.object(CLOCK2),
1506
- tx.pure.u64(ctokenAmount)
1507
- ]
1508
- });
1509
- const exemptionType = `${SUILEND_PACKAGE}::lending_market::RateLimiterExemption<${LENDING_MARKET_TYPE}, ${assetInfo.type}>`;
1510
- const [none] = tx.moveCall({
1511
- target: "0x1::option::none",
1512
- typeArguments: [exemptionType]
1513
- });
1514
- const [coin] = tx.moveCall({
1515
- target: `${pkg}::lending_market::redeem_ctokens_and_withdraw_liquidity`,
1516
- typeArguments: [LENDING_MARKET_TYPE, assetInfo.type],
1517
- arguments: [
1518
- tx.object(LENDING_MARKET_ID),
1519
- tx.pure.u64(reserve.arrayIndex),
1520
- tx.object(CLOCK2),
1521
- ctokens,
1522
- none
1512
+ tx.pure("u64", BigInt(withdrawArg))
1523
1513
  ]
1524
1514
  });
1515
+ const coin = this.redeemCtokens(tx, pkg, reserve, assetInfo.type, assetKey, ctokens);
1525
1516
  tx.transferObjects([coin], address);
1526
1517
  return { tx, effectiveAmount };
1527
1518
  }
@@ -1551,14 +1542,24 @@ var SuilendAdapter = class {
1551
1542
  tx.pure.u64(ctokenAmount)
1552
1543
  ]
1553
1544
  });
1554
- const exemptionType = `${SUILEND_PACKAGE}::lending_market::RateLimiterExemption<${LENDING_MARKET_TYPE}, ${assetInfo.type}>`;
1545
+ const coin = this.redeemCtokens(tx, pkg, reserve, assetInfo.type, assetKey, ctokens);
1546
+ return { coin, effectiveAmount };
1547
+ }
1548
+ /**
1549
+ * 3-step cToken redemption matching the official Suilend SDK flow:
1550
+ * 1. redeem_ctokens_and_withdraw_liquidity_request — creates a LiquidityRequest
1551
+ * 2. unstake_sui_from_staker — (SUI only) unstakes from validators to replenish available_liquidity
1552
+ * 3. fulfill_liquidity_request — splits underlying tokens from the reserve
1553
+ */
1554
+ redeemCtokens(tx, pkg, reserve, coinType, assetKey, ctokens) {
1555
+ const exemptionType = `${SUILEND_PACKAGE}::lending_market::RateLimiterExemption<${LENDING_MARKET_TYPE}, ${coinType}>`;
1555
1556
  const [none] = tx.moveCall({
1556
1557
  target: "0x1::option::none",
1557
1558
  typeArguments: [exemptionType]
1558
1559
  });
1559
- const [coin] = tx.moveCall({
1560
- target: `${pkg}::lending_market::redeem_ctokens_and_withdraw_liquidity`,
1561
- typeArguments: [LENDING_MARKET_TYPE, assetInfo.type],
1560
+ const [liquidityRequest] = tx.moveCall({
1561
+ target: `${pkg}::lending_market::redeem_ctokens_and_withdraw_liquidity_request`,
1562
+ typeArguments: [LENDING_MARKET_TYPE, coinType],
1562
1563
  arguments: [
1563
1564
  tx.object(LENDING_MARKET_ID),
1564
1565
  tx.pure.u64(reserve.arrayIndex),
@@ -1567,7 +1568,28 @@ var SuilendAdapter = class {
1567
1568
  none
1568
1569
  ]
1569
1570
  });
1570
- return { coin, effectiveAmount };
1571
+ if (assetKey === "SUI") {
1572
+ tx.moveCall({
1573
+ target: `${pkg}::lending_market::unstake_sui_from_staker`,
1574
+ typeArguments: [LENDING_MARKET_TYPE],
1575
+ arguments: [
1576
+ tx.object(LENDING_MARKET_ID),
1577
+ tx.pure.u64(reserve.arrayIndex),
1578
+ liquidityRequest,
1579
+ tx.object(SUI_SYSTEM_STATE2)
1580
+ ]
1581
+ });
1582
+ }
1583
+ const [coin] = tx.moveCall({
1584
+ target: `${pkg}::lending_market::fulfill_liquidity_request`,
1585
+ typeArguments: [LENDING_MARKET_TYPE, coinType],
1586
+ arguments: [
1587
+ tx.object(LENDING_MARKET_ID),
1588
+ tx.pure.u64(reserve.arrayIndex),
1589
+ liquidityRequest
1590
+ ]
1591
+ });
1592
+ return coin;
1571
1593
  }
1572
1594
  async addSaveToTx(tx, address, coin, asset, options) {
1573
1595
  const assetKey = asset in SUPPORTED_ASSETS ? asset : "USDC";