@t2000/sdk 0.16.16 → 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.
- package/dist/adapters/index.cjs +47 -25
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +47 -25
- package/dist/adapters/index.js.map +1 -1
- package/dist/{index-BOkO4S7r.d.cts → index-BRjfwac2.d.cts} +7 -0
- package/dist/{index-BOkO4S7r.d.ts → index-BRjfwac2.d.ts} +7 -0
- package/dist/index.cjs +51 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +51 -30
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/LICENSE +0 -21
package/dist/adapters/index.cjs
CHANGED
|
@@ -1135,6 +1135,7 @@ var CetusAdapter = class {
|
|
|
1135
1135
|
var WAD = 1e18;
|
|
1136
1136
|
var MIN_HEALTH_FACTOR2 = 1.5;
|
|
1137
1137
|
var CLOCK2 = "0x6";
|
|
1138
|
+
var SUI_SYSTEM_STATE2 = "0x5";
|
|
1138
1139
|
var LENDING_MARKET_ID = "0x84030d26d85eaa7035084a057f2f11f701b7e2e4eda87551becbc7c97505ece1";
|
|
1139
1140
|
var LENDING_MARKET_TYPE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL";
|
|
1140
1141
|
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
@@ -1150,6 +1151,9 @@ var descriptor3 = {
|
|
|
1150
1151
|
"lending_market::create_obligation": "save",
|
|
1151
1152
|
"lending_market::withdraw_ctokens": "withdraw",
|
|
1152
1153
|
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
1154
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
|
|
1155
|
+
"lending_market::fulfill_liquidity_request": "withdraw",
|
|
1156
|
+
"lending_market::unstake_sui_from_staker": "withdraw",
|
|
1153
1157
|
"lending_market::borrow": "borrow",
|
|
1154
1158
|
"lending_market::repay": "repay"
|
|
1155
1159
|
}
|
|
@@ -1494,7 +1498,9 @@ var SuilendAdapter = class {
|
|
|
1494
1498
|
const deposited = dep ? dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals : 0;
|
|
1495
1499
|
const effectiveAmount = Math.min(amount, deposited);
|
|
1496
1500
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on Suilend`);
|
|
1497
|
-
const
|
|
1501
|
+
const U64_MAX = "18446744073709551615";
|
|
1502
|
+
const isFullWithdraw = dep && effectiveAmount >= deposited * 0.999;
|
|
1503
|
+
const withdrawArg = isFullWithdraw ? U64_MAX : String(Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio));
|
|
1498
1504
|
const tx = new transactions.Transaction();
|
|
1499
1505
|
tx.setSender(address);
|
|
1500
1506
|
const [ctokens] = tx.moveCall({
|
|
@@ -1505,25 +1511,10 @@ var SuilendAdapter = class {
|
|
|
1505
1511
|
tx.pure.u64(reserve.arrayIndex),
|
|
1506
1512
|
tx.object(caps[0].id),
|
|
1507
1513
|
tx.object(CLOCK2),
|
|
1508
|
-
tx.pure
|
|
1509
|
-
]
|
|
1510
|
-
});
|
|
1511
|
-
const exemptionType = `${SUILEND_PACKAGE}::lending_market::RateLimiterExemption<${LENDING_MARKET_TYPE}, ${assetInfo.type}>`;
|
|
1512
|
-
const [none] = tx.moveCall({
|
|
1513
|
-
target: "0x1::option::none",
|
|
1514
|
-
typeArguments: [exemptionType]
|
|
1515
|
-
});
|
|
1516
|
-
const [coin] = tx.moveCall({
|
|
1517
|
-
target: `${pkg}::lending_market::redeem_ctokens_and_withdraw_liquidity`,
|
|
1518
|
-
typeArguments: [LENDING_MARKET_TYPE, assetInfo.type],
|
|
1519
|
-
arguments: [
|
|
1520
|
-
tx.object(LENDING_MARKET_ID),
|
|
1521
|
-
tx.pure.u64(reserve.arrayIndex),
|
|
1522
|
-
tx.object(CLOCK2),
|
|
1523
|
-
ctokens,
|
|
1524
|
-
none
|
|
1514
|
+
tx.pure("u64", BigInt(withdrawArg))
|
|
1525
1515
|
]
|
|
1526
1516
|
});
|
|
1517
|
+
const coin = this.redeemCtokens(tx, pkg, reserve, assetInfo.type, assetKey, ctokens);
|
|
1527
1518
|
tx.transferObjects([coin], address);
|
|
1528
1519
|
return { tx, effectiveAmount };
|
|
1529
1520
|
}
|
|
@@ -1541,7 +1532,7 @@ var SuilendAdapter = class {
|
|
|
1541
1532
|
const deposited = dep ? dep.ctokenAmount * ratio / 10 ** reserve.mintDecimals : 0;
|
|
1542
1533
|
const effectiveAmount = Math.min(amount, deposited);
|
|
1543
1534
|
if (effectiveAmount <= 0) throw new T2000Error("NO_COLLATERAL", `Nothing to withdraw for ${assetInfo.displayName} on Suilend`);
|
|
1544
|
-
const
|
|
1535
|
+
const ctokenAmount = dep && effectiveAmount >= deposited * 0.999 ? dep.ctokenAmount : Math.floor(effectiveAmount * 10 ** reserve.mintDecimals / ratio);
|
|
1545
1536
|
const [ctokens] = tx.moveCall({
|
|
1546
1537
|
target: `${pkg}::lending_market::withdraw_ctokens`,
|
|
1547
1538
|
typeArguments: [LENDING_MARKET_TYPE, assetInfo.type],
|
|
@@ -1550,17 +1541,27 @@ var SuilendAdapter = class {
|
|
|
1550
1541
|
tx.pure.u64(reserve.arrayIndex),
|
|
1551
1542
|
tx.object(caps[0].id),
|
|
1552
1543
|
tx.object(CLOCK2),
|
|
1553
|
-
tx.pure.u64(
|
|
1544
|
+
tx.pure.u64(ctokenAmount)
|
|
1554
1545
|
]
|
|
1555
1546
|
});
|
|
1556
|
-
const
|
|
1547
|
+
const coin = this.redeemCtokens(tx, pkg, reserve, assetInfo.type, assetKey, ctokens);
|
|
1548
|
+
return { coin, effectiveAmount };
|
|
1549
|
+
}
|
|
1550
|
+
/**
|
|
1551
|
+
* 3-step cToken redemption matching the official Suilend SDK flow:
|
|
1552
|
+
* 1. redeem_ctokens_and_withdraw_liquidity_request — creates a LiquidityRequest
|
|
1553
|
+
* 2. unstake_sui_from_staker — (SUI only) unstakes from validators to replenish available_liquidity
|
|
1554
|
+
* 3. fulfill_liquidity_request — splits underlying tokens from the reserve
|
|
1555
|
+
*/
|
|
1556
|
+
redeemCtokens(tx, pkg, reserve, coinType, assetKey, ctokens) {
|
|
1557
|
+
const exemptionType = `${SUILEND_PACKAGE}::lending_market::RateLimiterExemption<${LENDING_MARKET_TYPE}, ${coinType}>`;
|
|
1557
1558
|
const [none] = tx.moveCall({
|
|
1558
1559
|
target: "0x1::option::none",
|
|
1559
1560
|
typeArguments: [exemptionType]
|
|
1560
1561
|
});
|
|
1561
|
-
const [
|
|
1562
|
-
target: `${pkg}::lending_market::
|
|
1563
|
-
typeArguments: [LENDING_MARKET_TYPE,
|
|
1562
|
+
const [liquidityRequest] = tx.moveCall({
|
|
1563
|
+
target: `${pkg}::lending_market::redeem_ctokens_and_withdraw_liquidity_request`,
|
|
1564
|
+
typeArguments: [LENDING_MARKET_TYPE, coinType],
|
|
1564
1565
|
arguments: [
|
|
1565
1566
|
tx.object(LENDING_MARKET_ID),
|
|
1566
1567
|
tx.pure.u64(reserve.arrayIndex),
|
|
@@ -1569,7 +1570,28 @@ var SuilendAdapter = class {
|
|
|
1569
1570
|
none
|
|
1570
1571
|
]
|
|
1571
1572
|
});
|
|
1572
|
-
|
|
1573
|
+
if (assetKey === "SUI") {
|
|
1574
|
+
tx.moveCall({
|
|
1575
|
+
target: `${pkg}::lending_market::unstake_sui_from_staker`,
|
|
1576
|
+
typeArguments: [LENDING_MARKET_TYPE],
|
|
1577
|
+
arguments: [
|
|
1578
|
+
tx.object(LENDING_MARKET_ID),
|
|
1579
|
+
tx.pure.u64(reserve.arrayIndex),
|
|
1580
|
+
liquidityRequest,
|
|
1581
|
+
tx.object(SUI_SYSTEM_STATE2)
|
|
1582
|
+
]
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
const [coin] = tx.moveCall({
|
|
1586
|
+
target: `${pkg}::lending_market::fulfill_liquidity_request`,
|
|
1587
|
+
typeArguments: [LENDING_MARKET_TYPE, coinType],
|
|
1588
|
+
arguments: [
|
|
1589
|
+
tx.object(LENDING_MARKET_ID),
|
|
1590
|
+
tx.pure.u64(reserve.arrayIndex),
|
|
1591
|
+
liquidityRequest
|
|
1592
|
+
]
|
|
1593
|
+
});
|
|
1594
|
+
return coin;
|
|
1573
1595
|
}
|
|
1574
1596
|
async addSaveToTx(tx, address, coin, asset, options) {
|
|
1575
1597
|
const assetKey = asset in SUPPORTED_ASSETS ? asset : "USDC";
|