@t2000/sdk 0.19.20 → 0.19.21
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 +23 -6
- 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 +23 -6
- package/dist/adapters/index.js.map +1 -1
- package/dist/{index-DAxuyiS2.d.cts → index-CRyFiIZm.d.cts} +2 -0
- package/dist/{index-DAxuyiS2.d.ts → index-CRyFiIZm.d.ts} +2 -0
- package/dist/index.cjs +39 -12
- 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 +39 -12
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/adapters/index.cjs
CHANGED
|
@@ -294,6 +294,7 @@ function sdkOptions(client) {
|
|
|
294
294
|
return { env: "prod", client, cacheTime: 0, disableCache: true };
|
|
295
295
|
}
|
|
296
296
|
async function refreshOracle(tx, client, address, options) {
|
|
297
|
+
if (options?.skipOracle) return;
|
|
297
298
|
const origInfo = console.info;
|
|
298
299
|
const origWarn = console.warn;
|
|
299
300
|
console.info = (...args) => {
|
|
@@ -461,13 +462,14 @@ async function buildSaveTx(client, address, amount, options = {}) {
|
|
|
461
462
|
const assetInfo = resolveAssetInfo(asset);
|
|
462
463
|
const coins = await fetchCoins(client, address, assetInfo.type);
|
|
463
464
|
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins found`);
|
|
465
|
+
const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
|
|
464
466
|
const tx = new transactions.Transaction();
|
|
465
467
|
tx.setSender(address);
|
|
466
468
|
const coinObj = mergeCoins(tx, coins);
|
|
467
469
|
if (options.collectFee) {
|
|
468
470
|
addCollectFeeToTx(tx, coinObj, "save");
|
|
469
471
|
}
|
|
470
|
-
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
472
|
+
const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
|
|
471
473
|
try {
|
|
472
474
|
await lending.depositCoinPTB(tx, assetInfo.type, coinObj, {
|
|
473
475
|
...sdkOptions(client),
|
|
@@ -588,12 +590,16 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
588
590
|
const assetInfo = resolveAssetInfo(asset);
|
|
589
591
|
const coins = await fetchCoins(client, address, assetInfo.type);
|
|
590
592
|
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with`);
|
|
593
|
+
const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
|
|
591
594
|
const tx = new transactions.Transaction();
|
|
592
595
|
tx.setSender(address);
|
|
593
596
|
const coinObj = mergeCoins(tx, coins);
|
|
594
|
-
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
597
|
+
const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
|
|
595
598
|
const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
|
|
596
|
-
await refreshOracle(tx, client, address, {
|
|
599
|
+
await refreshOracle(tx, client, address, {
|
|
600
|
+
skipPythUpdate: options.sponsored,
|
|
601
|
+
skipOracle: options.skipOracle
|
|
602
|
+
});
|
|
597
603
|
try {
|
|
598
604
|
await lending.repayCoinPTB(tx, assetInfo.type, repayCoin, {
|
|
599
605
|
...sdkOptions(client),
|
|
@@ -746,7 +752,11 @@ var NaviAdapter = class {
|
|
|
746
752
|
}
|
|
747
753
|
async buildRepayTx(address, amount, asset, options) {
|
|
748
754
|
const normalized = normalizeAsset(asset);
|
|
749
|
-
const tx = await buildRepayTx(this.client, address, amount, {
|
|
755
|
+
const tx = await buildRepayTx(this.client, address, amount, {
|
|
756
|
+
asset: normalized,
|
|
757
|
+
sponsored: options?.sponsored,
|
|
758
|
+
skipOracle: options?.skipOracle
|
|
759
|
+
});
|
|
750
760
|
return { tx };
|
|
751
761
|
}
|
|
752
762
|
async maxWithdraw(address, _asset) {
|
|
@@ -1380,16 +1390,23 @@ var SuilendAdapter = class {
|
|
|
1380
1390
|
if (obligationOwnerCaps.length === 0 || obligations.length === 0) return [];
|
|
1381
1391
|
const ob = obligations[0];
|
|
1382
1392
|
const rewards = [];
|
|
1393
|
+
const WAD = 1e18;
|
|
1383
1394
|
for (const dep of ob.deposits) {
|
|
1384
|
-
|
|
1395
|
+
const urm = dep.userRewardManager;
|
|
1396
|
+
for (const rw of dep.reserve.depositsPoolRewardManager?.poolRewards ?? []) {
|
|
1385
1397
|
if (rw.endTimeMs <= Date.now()) continue;
|
|
1398
|
+
let claimableAmount = 0;
|
|
1399
|
+
const userReward = urm?.rewards?.[rw.rewardIndex];
|
|
1400
|
+
if (userReward?.earnedRewards) {
|
|
1401
|
+
claimableAmount = Number(BigInt(userReward.earnedRewards.value.toString())) / WAD / 10 ** rw.mintDecimals;
|
|
1402
|
+
}
|
|
1386
1403
|
const symbol = rw.symbol || rw.coinType.split("::").pop() || "UNKNOWN";
|
|
1387
1404
|
rewards.push({
|
|
1388
1405
|
protocol: "suilend",
|
|
1389
1406
|
asset: this.resolveSymbol(dep.coinType),
|
|
1390
1407
|
coinType: rw.coinType,
|
|
1391
1408
|
symbol,
|
|
1392
|
-
amount:
|
|
1409
|
+
amount: claimableAmount,
|
|
1393
1410
|
estimatedValueUsd: 0
|
|
1394
1411
|
});
|
|
1395
1412
|
}
|