@t2000/sdk 2.13.2 → 2.14.0
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 +12 -29
- 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 +13 -30
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +135 -234
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -80
- package/dist/index.d.ts +74 -80
- package/dist/index.js +136 -235
- package/dist/index.js.map +1 -1
- package/dist/{types-BY6ovQGK.d.cts → types-1WUNZK-9.d.cts} +1 -1
- package/dist/{types-epj9U13o.d.cts → types-CFJrgLm2.d.cts} +21 -13
- package/dist/{types-epj9U13o.d.ts → types-CFJrgLm2.d.ts} +21 -13
- package/dist/{types-WeZQDV54.d.ts → types-D65N3sBO.d.ts} +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { L as LendingAdapter, a as LendingRates, b as AdapterPositions, A as AdapterCapability, H as HealthInfo, c as AdapterTxResult, P as PendingReward } from '../descriptors-DqIb4AnV.cjs';
|
|
2
2
|
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-DqIb4AnV.cjs';
|
|
3
|
-
import { b as MaxWithdrawResult, M as MaxBorrowResult } from '../types-
|
|
3
|
+
import { b as MaxWithdrawResult, M as MaxBorrowResult } from '../types-CFJrgLm2.cjs';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
6
6
|
import '@cetusprotocol/aggregator-sdk';
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { L as LendingAdapter, a as LendingRates, b as AdapterPositions, A as AdapterCapability, H as HealthInfo, c as AdapterTxResult, P as PendingReward } from '../descriptors-DqIb4AnV.js';
|
|
2
2
|
export { d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from '../descriptors-DqIb4AnV.js';
|
|
3
|
-
import { b as MaxWithdrawResult, M as MaxBorrowResult } from '../types-
|
|
3
|
+
import { b as MaxWithdrawResult, M as MaxBorrowResult } from '../types-CFJrgLm2.js';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
6
6
|
import '@cetusprotocol/aggregator-sdk';
|
package/dist/adapters/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transaction } from '@mysten/sui/transactions';
|
|
1
|
+
import { Transaction, coinWithBalance } from '@mysten/sui/transactions';
|
|
2
2
|
import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';
|
|
3
3
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
4
4
|
import { SuiPriceServiceConnection, SuiPythClient } from '@pythnetwork/pyth-sui-js';
|
|
@@ -4301,26 +4301,6 @@ function resolveAssetInfo(asset) {
|
|
|
4301
4301
|
}
|
|
4302
4302
|
throw new T2000Error("ASSET_NOT_SUPPORTED", `Unknown asset: ${asset}`);
|
|
4303
4303
|
}
|
|
4304
|
-
async function fetchCoins(client, owner, coinType) {
|
|
4305
|
-
const all = [];
|
|
4306
|
-
let cursor;
|
|
4307
|
-
let hasNext = true;
|
|
4308
|
-
while (hasNext) {
|
|
4309
|
-
const page = await client.getCoins({ owner, coinType, cursor: cursor ?? void 0 });
|
|
4310
|
-
all.push(...page.data.map((c) => ({ coinObjectId: c.coinObjectId, balance: c.balance })));
|
|
4311
|
-
cursor = page.nextCursor;
|
|
4312
|
-
hasNext = page.hasNextPage;
|
|
4313
|
-
}
|
|
4314
|
-
return all;
|
|
4315
|
-
}
|
|
4316
|
-
function mergeCoins(tx, coins) {
|
|
4317
|
-
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No coins to merge");
|
|
4318
|
-
const primary = tx.object(coins[0].coinObjectId);
|
|
4319
|
-
if (coins.length > 1) {
|
|
4320
|
-
tx.mergeCoins(primary, coins.slice(1).map((c) => tx.object(c.coinObjectId)));
|
|
4321
|
-
}
|
|
4322
|
-
return primary;
|
|
4323
|
-
}
|
|
4324
4304
|
async function getPositions(client, address) {
|
|
4325
4305
|
try {
|
|
4326
4306
|
const naviPositions = await $e(address, {
|
|
@@ -4411,13 +4391,15 @@ async function buildSaveTx(client, address, amount, options = {}) {
|
|
|
4411
4391
|
}
|
|
4412
4392
|
const asset = options.asset ?? "USDC";
|
|
4413
4393
|
const assetInfo = resolveAssetInfo(asset);
|
|
4414
|
-
const
|
|
4415
|
-
|
|
4416
|
-
|
|
4394
|
+
const balResp = await client.getBalance({ owner: address, coinType: assetInfo.type });
|
|
4395
|
+
const totalBalance = BigInt(balResp.totalBalance);
|
|
4396
|
+
if (totalBalance === 0n) {
|
|
4397
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} balance found`);
|
|
4398
|
+
}
|
|
4417
4399
|
const tx = new Transaction();
|
|
4418
4400
|
tx.setSender(address);
|
|
4419
|
-
const coinObj = mergeCoins(tx, coins);
|
|
4420
4401
|
const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
|
|
4402
|
+
const coinObj = coinWithBalance({ type: assetInfo.type, balance: BigInt(rawAmount) })(tx);
|
|
4421
4403
|
try {
|
|
4422
4404
|
await Ce(tx, assetInfo.type, coinObj, {
|
|
4423
4405
|
...sdkOptions(client),
|
|
@@ -4549,18 +4531,19 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
4549
4531
|
}
|
|
4550
4532
|
const asset = options.asset ?? "USDC";
|
|
4551
4533
|
const assetInfo = resolveAssetInfo(asset);
|
|
4552
|
-
const
|
|
4553
|
-
|
|
4554
|
-
|
|
4534
|
+
const balResp = await client.getBalance({ owner: address, coinType: assetInfo.type });
|
|
4535
|
+
const totalBalance = BigInt(balResp.totalBalance);
|
|
4536
|
+
if (totalBalance === 0n) {
|
|
4537
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} to repay with. Withdraw some savings first to get cash.`);
|
|
4538
|
+
}
|
|
4555
4539
|
const rawRequested = Number(stableToRaw(amount, assetInfo.decimals));
|
|
4556
4540
|
if (Number(totalBalance) < rawRequested && Number(totalBalance) < 1e3) {
|
|
4557
4541
|
throw new T2000Error("INSUFFICIENT_BALANCE", `Not enough ${assetInfo.displayName} to repay (need $${amount.toFixed(2)}, wallet has ~$${(Number(totalBalance) / 10 ** assetInfo.decimals).toFixed(4)}). Withdraw some savings first.`);
|
|
4558
4542
|
}
|
|
4559
4543
|
const tx = new Transaction();
|
|
4560
4544
|
tx.setSender(address);
|
|
4561
|
-
const coinObj = mergeCoins(tx, coins);
|
|
4562
4545
|
const rawAmount = Math.min(rawRequested, Number(totalBalance));
|
|
4563
|
-
const
|
|
4546
|
+
const repayCoin = coinWithBalance({ type: assetInfo.type, balance: BigInt(rawAmount) })(tx);
|
|
4564
4547
|
await refreshOracle(tx, client, address, {
|
|
4565
4548
|
skipOracle: options.skipOracle,
|
|
4566
4549
|
skipPythUpdate: options.skipPythUpdate
|