@t2000/sdk 0.2.1 → 0.2.4

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/index.d.cts CHANGED
@@ -44,6 +44,7 @@ interface SaveResult {
44
44
  fee: number;
45
45
  gasCost: number;
46
46
  gasMethod: GasMethod;
47
+ savingsBalance: number;
47
48
  }
48
49
  interface WithdrawResult {
49
50
  success: boolean;
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ interface SaveResult {
44
44
  fee: number;
45
45
  gasCost: number;
46
46
  gasMethod: GasMethod;
47
+ savingsBalance: number;
47
48
  }
48
49
  interface WithdrawResult {
49
50
  success: boolean;
package/dist/index.js CHANGED
@@ -272,12 +272,14 @@ async function buildSendTx({
272
272
  }
273
273
 
274
274
  // src/wallet/balance.ts
275
- var _cachedSuiPrice = 3.5;
275
+ var _cachedSuiPrice = 0;
276
276
  var _priceLastFetched = 0;
277
277
  var PRICE_CACHE_TTL_MS = 6e4;
278
278
  async function fetchSuiPrice(client) {
279
279
  const now = Date.now();
280
- if (now - _priceLastFetched < PRICE_CACHE_TTL_MS) return _cachedSuiPrice;
280
+ if (_cachedSuiPrice > 0 && now - _priceLastFetched < PRICE_CACHE_TTL_MS) {
281
+ return _cachedSuiPrice;
282
+ }
281
283
  try {
282
284
  const pool = await client.getObject({
283
285
  id: CETUS_USDC_SUI_POOL,
@@ -290,7 +292,7 @@ async function fetchSuiPrice(client) {
290
292
  const Q64 = 2n ** 64n;
291
293
  const sqrtPriceFloat = Number(currentSqrtPrice) / Number(Q64);
292
294
  const rawPrice = sqrtPriceFloat * sqrtPriceFloat;
293
- const price = rawPrice * 1e3;
295
+ const price = 1e3 / rawPrice;
294
296
  if (price > 0.01 && price < 1e3) {
295
297
  _cachedSuiPrice = price;
296
298
  _priceLastFetched = now;
@@ -1056,6 +1058,10 @@ var T2000 = class _T2000 extends EventEmitter {
1056
1058
  }
1057
1059
  // -- Savings --
1058
1060
  async save(params) {
1061
+ const asset = (params.asset ?? "USDC").toUpperCase();
1062
+ if (asset !== "USDC") {
1063
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Only USDC is supported for save. Got: ${asset}`);
1064
+ }
1059
1065
  let amount;
1060
1066
  if (params.amount === "all") {
1061
1067
  const bal = await queryBalance(this.client, this._address);
@@ -1080,6 +1086,12 @@ var T2000 = class _T2000 extends EventEmitter {
1080
1086
  const rates = await getRates(this.client);
1081
1087
  reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
1082
1088
  this.emitBalanceChange("USDC", saveAmount, "save", gasResult.digest);
1089
+ let savingsBalance = saveAmount - fee.amount;
1090
+ try {
1091
+ const positions = await this.positions();
1092
+ savingsBalance = positions.positions.filter((p) => p.type === "save").reduce((sum, p) => sum + p.amount, 0);
1093
+ } catch {
1094
+ }
1083
1095
  return {
1084
1096
  success: true,
1085
1097
  tx: gasResult.digest,
@@ -1087,10 +1099,15 @@ var T2000 = class _T2000 extends EventEmitter {
1087
1099
  apy: rates.USDC.saveApy,
1088
1100
  fee: fee.amount,
1089
1101
  gasCost: gasResult.gasCostSui,
1090
- gasMethod: gasResult.gasMethod
1102
+ gasMethod: gasResult.gasMethod,
1103
+ savingsBalance
1091
1104
  };
1092
1105
  }
1093
1106
  async withdraw(params) {
1107
+ const asset = (params.asset ?? "USDC").toUpperCase();
1108
+ if (asset !== "USDC") {
1109
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Only USDC is supported for withdraw. Got: ${asset}`);
1110
+ }
1094
1111
  let amount;
1095
1112
  if (params.amount === "all") {
1096
1113
  const maxResult = await this.maxWithdraw();
@@ -1137,6 +1154,10 @@ var T2000 = class _T2000 extends EventEmitter {
1137
1154
  }
1138
1155
  // -- Borrowing --
1139
1156
  async borrow(params) {
1157
+ const asset = (params.asset ?? "USDC").toUpperCase();
1158
+ if (asset !== "USDC") {
1159
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Only USDC is supported for borrow. Got: ${asset}`);
1160
+ }
1140
1161
  const maxResult = await this.maxBorrow();
1141
1162
  if (params.amount > maxResult.maxAmount) {
1142
1163
  throw new T2000Error("HEALTH_FACTOR_TOO_LOW", `Max safe borrow: $${maxResult.maxAmount.toFixed(2)}`, {
@@ -1165,6 +1186,10 @@ var T2000 = class _T2000 extends EventEmitter {
1165
1186
  };
1166
1187
  }
1167
1188
  async repay(params) {
1189
+ const asset = (params.asset ?? "USDC").toUpperCase();
1190
+ if (asset !== "USDC") {
1191
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Only USDC is supported for repay. Got: ${asset}`);
1192
+ }
1168
1193
  let amount;
1169
1194
  if (params.amount === "all") {
1170
1195
  const hf2 = await this.healthFactor();