@t2000/sdk 0.8.4 → 0.8.6
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 +16 -11
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +16 -11
- package/dist/adapters/index.js.map +1 -1
- package/dist/index.cjs +32 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +32 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -237,8 +237,8 @@ declare function getDecimals(asset: SupportedAsset): number;
|
|
|
237
237
|
declare function formatUsd(amount: number): string;
|
|
238
238
|
declare function formatSui(amount: number): string;
|
|
239
239
|
/**
|
|
240
|
-
* Case-insensitive lookup against SUPPORTED_ASSETS keys.
|
|
241
|
-
* 'usde' → 'USDe', '
|
|
240
|
+
* Case-insensitive lookup against SUPPORTED_ASSETS keys AND display names.
|
|
241
|
+
* 'usde' → 'USDe', 'suiusde' → 'USDe', 'suiusdt' → 'USDT', 'usdsui' → 'USDsui'.
|
|
242
242
|
* Returns the original input if not found so downstream validation can reject it.
|
|
243
243
|
*/
|
|
244
244
|
declare function normalizeAsset(input: string): string;
|
|
@@ -282,7 +282,7 @@ declare function simulateTransaction(client: SuiJsonRpcClient, tx: Transaction,
|
|
|
282
282
|
declare function throwIfSimulationFailed(sim: SimulationResult): void;
|
|
283
283
|
|
|
284
284
|
declare function getPoolPrice(client: SuiJsonRpcClient): Promise<number>;
|
|
285
|
-
declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset:
|
|
285
|
+
declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: string, toAsset: string, amount: number): Promise<{
|
|
286
286
|
expectedOutput: number;
|
|
287
287
|
priceImpact: number;
|
|
288
288
|
poolPrice: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -237,8 +237,8 @@ declare function getDecimals(asset: SupportedAsset): number;
|
|
|
237
237
|
declare function formatUsd(amount: number): string;
|
|
238
238
|
declare function formatSui(amount: number): string;
|
|
239
239
|
/**
|
|
240
|
-
* Case-insensitive lookup against SUPPORTED_ASSETS keys.
|
|
241
|
-
* 'usde' → 'USDe', '
|
|
240
|
+
* Case-insensitive lookup against SUPPORTED_ASSETS keys AND display names.
|
|
241
|
+
* 'usde' → 'USDe', 'suiusde' → 'USDe', 'suiusdt' → 'USDT', 'usdsui' → 'USDsui'.
|
|
242
242
|
* Returns the original input if not found so downstream validation can reject it.
|
|
243
243
|
*/
|
|
244
244
|
declare function normalizeAsset(input: string): string;
|
|
@@ -282,7 +282,7 @@ declare function simulateTransaction(client: SuiJsonRpcClient, tx: Transaction,
|
|
|
282
282
|
declare function throwIfSimulationFailed(sim: SimulationResult): void;
|
|
283
283
|
|
|
284
284
|
declare function getPoolPrice(client: SuiJsonRpcClient): Promise<number>;
|
|
285
|
-
declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset:
|
|
285
|
+
declare function getSwapQuote(client: SuiJsonRpcClient, fromAsset: string, toAsset: string, amount: number): Promise<{
|
|
286
286
|
expectedOutput: number;
|
|
287
287
|
priceImpact: number;
|
|
288
288
|
poolPrice: number;
|
package/dist/index.js
CHANGED
|
@@ -276,9 +276,13 @@ function formatSui(amount) {
|
|
|
276
276
|
if (amount < 1e-3) return `${amount.toFixed(6)} SUI`;
|
|
277
277
|
return `${amount.toFixed(3)} SUI`;
|
|
278
278
|
}
|
|
279
|
-
var ASSET_LOOKUP = new Map(
|
|
280
|
-
|
|
281
|
-
);
|
|
279
|
+
var ASSET_LOOKUP = /* @__PURE__ */ new Map();
|
|
280
|
+
for (const [key, info] of Object.entries(SUPPORTED_ASSETS)) {
|
|
281
|
+
ASSET_LOOKUP.set(key.toUpperCase(), key);
|
|
282
|
+
if (info.displayName && info.displayName.toUpperCase() !== key.toUpperCase()) {
|
|
283
|
+
ASSET_LOOKUP.set(info.displayName.toUpperCase(), key);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
282
286
|
function normalizeAsset(input) {
|
|
283
287
|
return ASSET_LOOKUP.get(input.toUpperCase()) ?? input;
|
|
284
288
|
}
|
|
@@ -1403,6 +1407,9 @@ async function buildSwapTx(params) {
|
|
|
1403
1407
|
const { client, address, fromAsset, toAsset, amount, maxSlippageBps = DEFAULT_SLIPPAGE_BPS } = params;
|
|
1404
1408
|
const fromInfo = SUPPORTED_ASSETS[fromAsset];
|
|
1405
1409
|
const toInfo = SUPPORTED_ASSETS[toAsset];
|
|
1410
|
+
if (!fromInfo || !toInfo) {
|
|
1411
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
|
|
1412
|
+
}
|
|
1406
1413
|
const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
|
|
1407
1414
|
const aggClient = createAggregatorClient(client, address);
|
|
1408
1415
|
const result = await aggClient.findRouters({
|
|
@@ -1455,6 +1462,9 @@ async function getPoolPrice(client) {
|
|
|
1455
1462
|
async function getSwapQuote(client, fromAsset, toAsset, amount) {
|
|
1456
1463
|
const fromInfo = SUPPORTED_ASSETS[fromAsset];
|
|
1457
1464
|
const toInfo = SUPPORTED_ASSETS[toAsset];
|
|
1465
|
+
if (!fromInfo || !toInfo) {
|
|
1466
|
+
throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
|
|
1467
|
+
}
|
|
1458
1468
|
const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
|
|
1459
1469
|
const poolPrice = await getPoolPrice(client);
|
|
1460
1470
|
try {
|
|
@@ -1506,19 +1516,14 @@ var CetusAdapter = class {
|
|
|
1506
1516
|
this.client = client;
|
|
1507
1517
|
}
|
|
1508
1518
|
async getQuote(from, to, amount) {
|
|
1509
|
-
return getSwapQuote(
|
|
1510
|
-
this.client,
|
|
1511
|
-
from.toUpperCase(),
|
|
1512
|
-
to.toUpperCase(),
|
|
1513
|
-
amount
|
|
1514
|
-
);
|
|
1519
|
+
return getSwapQuote(this.client, from, to, amount);
|
|
1515
1520
|
}
|
|
1516
1521
|
async buildSwapTx(address, from, to, amount, maxSlippageBps) {
|
|
1517
1522
|
const result = await buildSwapTx({
|
|
1518
1523
|
client: this.client,
|
|
1519
1524
|
address,
|
|
1520
|
-
fromAsset: from
|
|
1521
|
-
toAsset: to
|
|
1525
|
+
fromAsset: from,
|
|
1526
|
+
toAsset: to,
|
|
1522
1527
|
amount,
|
|
1523
1528
|
maxSlippageBps
|
|
1524
1529
|
});
|
|
@@ -2793,6 +2798,22 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2793
2798
|
const current = savePositions.reduce(
|
|
2794
2799
|
(worst, p) => p.apy < worst.apy ? p : worst
|
|
2795
2800
|
);
|
|
2801
|
+
const withdrawAdapter = this.registry.getLending(current.protocolId);
|
|
2802
|
+
if (withdrawAdapter) {
|
|
2803
|
+
try {
|
|
2804
|
+
const maxResult = await withdrawAdapter.maxWithdraw(this._address, current.asset);
|
|
2805
|
+
if (maxResult.maxAmount < current.amount) {
|
|
2806
|
+
current.amount = Math.max(0, maxResult.maxAmount - 0.01);
|
|
2807
|
+
}
|
|
2808
|
+
} catch {
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
if (current.amount <= 0.01) {
|
|
2812
|
+
throw new T2000Error(
|
|
2813
|
+
"HEALTH_FACTOR_TOO_LOW",
|
|
2814
|
+
"Cannot rebalance \u2014 active borrows prevent safe withdrawal. Repay some debt first."
|
|
2815
|
+
);
|
|
2816
|
+
}
|
|
2796
2817
|
const apyDiff = bestRate.rates.saveApy - current.apy;
|
|
2797
2818
|
const isSameProtocol = current.protocolId === bestRate.protocolId;
|
|
2798
2819
|
const isSameAsset = current.asset === bestRate.asset;
|
|
@@ -2904,7 +2925,6 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2904
2925
|
}
|
|
2905
2926
|
const txDigests = [];
|
|
2906
2927
|
let totalGasCost = 0;
|
|
2907
|
-
const withdrawAdapter = this.registry.getLending(current.protocolId);
|
|
2908
2928
|
if (!withdrawAdapter) throw new T2000Error("PROTOCOL_UNAVAILABLE", `Protocol ${current.protocolId} not found`);
|
|
2909
2929
|
const withdrawResult = await executeWithGas(this.client, this.keypair, async () => {
|
|
2910
2930
|
const built = await withdrawAdapter.buildWithdrawTx(this._address, current.amount, current.asset);
|